# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
736025 | 2023-05-05T06:48:17 Z | Hydrolyzed | Safety (NOI18_safety) | C++14 | 15 ms | 3800 KB |
/* * AUTHOR : Hydrolyzed~ * SCHOOL : RYW * TASK : Safety Subtask 4 * ALGO : Dynamic Programming * DATE : 5 May 2023 * */ #include <bits/stdc++.h> #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp> #include <ext/rope> #ifndef _DEBUG // @==== Libary ====@ // // @================@ // #endif using namespace std; using namespace __gnu_pbds; using namespace __gnu_cxx; template <typename T> using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update> ; // @=== Debugger ===@ // #ifdef _DEBUG #include "debug.hpp" #else #define dbg(...) 0 #endif // @================@ // using ll = long long; const int MxN = 200020; ll a[MxN]; struct slope_trick{ multiset<ll> ms_l, ms_r; ll min_y = 0; inline void add_line(ll value){ if(ms_l.upper_bound(value) != ms_l.end()){ ms_l.emplace(value); ms_l.emplace(value); } else{ ms_r.emplace(value); ms_r.emplace(value); } ll last = 0; if(ms_l.size() > ms_r.size()){ last = *ms_l.end(); ms_l.erase(ms_l.end()); ms_r.emplace(last); } else if(ms_r.size() > ms_l.size()){ last = *ms_r.begin(); ms_r.erase(ms_r.begin()); ms_l.emplace(last); } if(ms_l.size() + ms_r.size() != 2){ min_y += abs(last - value); } }; } dp; inline void solution(){ int n, h; cin >> n >> h; for(int i=1; i<=n; ++i){ cin >> a[i]; } for(int i=1; i<=n; ++i){ dp.add_line(a[i]); dbg(dp.min_y); } cout << dp.min_y; return ; } signed main(){ cin.tie(nullptr)->ios::sync_with_stdio(false); int q = 1; // cin >> q; while(q--){ solution(); cout << "\n"; } return 0; } // https://github.com/MasterIceZ/archive/tree/main/cpp-template
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 1 ms | 212 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Runtime error | 1 ms | 444 KB | Execution killed with signal 11 |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Runtime error | 1 ms | 468 KB | Execution killed with signal 6 |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Runtime error | 15 ms | 3800 KB | Execution killed with signal 6 |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 1 ms | 212 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 1 ms | 212 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 1 ms | 212 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 1 ms | 212 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 1 ms | 212 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |