# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
975292 | 2024-05-04T17:08:37 Z | Mr_Husanboy | Potatoes and fertilizers (LMIO19_bulves) | C++17 | 104 ms | 262144 KB |
//#pragma GCC optimize("Ofast,O3") //#pragma GCC target("avx,avx2") #include <bits/stdc++.h> using namespace std; #ifdef LOCAL #include "debugger.cpp" #else #define debug(...) #endif template<class T> int len(T &a){ return a.size(); } using ll = long long; using pii = pair<int,int>; #define all(a) (a).begin(), (a).end() #define ff first #define ss second string fileio = ""; mt19937 rng(chrono::high_resolution_clock::now().time_since_epoch().count()); const int MOD = 1e9 + 7; const int inf = 1e9; const ll infl = 1e18; const int maxn = 1e5 + 1; void solve(){ int n; cin >> n; vector<ll> dif(n + 1); for(int i = 1; i <= n; i ++){ int a, b; cin >> a >> b; dif[i] = a - b; } for(int i = 1; i <= n; i ++) dif[i] += dif[i - 1]; debug(dif); vector<ll> dp(dif[n] + 1, 0); for(int i = 1; i <= n; i ++){ vector<ll> tdp(dif[n] + 1, infl); for(int j = 0; j <= dif[n]; j ++){ if(j) tdp[j] = tdp[j - 1]; tdp[j] = min(tdp[j], dp[j] + abs(dif[i] - j)); } swap(dp, tdp); } cout << dp[dif[n]]; } int main(){ ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); auto start = chrono::high_resolution_clock::now(); #ifndef LOCAL if(fileio.size()){ freopen((fileio + ".in").c_str(), "r", stdin); freopen((fileio + ".out").c_str(), "w", stdout); } #endif int testcases = 1; #ifdef Tests cin >> testcases; #endif while(testcases --){ solve(); if(testcases) cout << '\n'; #ifdef LOCAL else cout << '\n'; cout << "_________________________" << endl; #endif } #ifdef LOCAL auto duration = chrono::duration_cast<chrono::microseconds>(chrono::high_resolution_clock::now() - start); cout << "time: " << (double)duration.count()/1000.0 << " milliseconds" << endl; #endif return 0; }
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 0 ms | 348 KB | Output is correct |
2 | Correct | 1 ms | 348 KB | Output is correct |
3 | Correct | 1 ms | 476 KB | Output is correct |
4 | Correct | 6 ms | 1116 KB | Output is correct |
5 | Correct | 12 ms | 1880 KB | Output is correct |
6 | Correct | 36 ms | 5588 KB | Output is correct |
7 | Correct | 74 ms | 11216 KB | Output is correct |
8 | Correct | 58 ms | 9228 KB | Output is correct |
9 | Correct | 56 ms | 8568 KB | Output is correct |
10 | Correct | 55 ms | 6228 KB | Output is correct |
11 | Correct | 48 ms | 6228 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 0 ms | 348 KB | Output is correct |
2 | Correct | 1 ms | 348 KB | Output is correct |
3 | Correct | 1 ms | 476 KB | Output is correct |
4 | Correct | 6 ms | 1116 KB | Output is correct |
5 | Correct | 12 ms | 1880 KB | Output is correct |
6 | Correct | 36 ms | 5588 KB | Output is correct |
7 | Correct | 74 ms | 11216 KB | Output is correct |
8 | Correct | 58 ms | 9228 KB | Output is correct |
9 | Correct | 56 ms | 8568 KB | Output is correct |
10 | Correct | 55 ms | 6228 KB | Output is correct |
11 | Correct | 48 ms | 6228 KB | Output is correct |
12 | Correct | 18 ms | 3100 KB | Output is correct |
13 | Correct | 51 ms | 6748 KB | Output is correct |
14 | Correct | 70 ms | 10892 KB | Output is correct |
15 | Correct | 76 ms | 9232 KB | Output is correct |
16 | Correct | 59 ms | 8528 KB | Output is correct |
17 | Correct | 53 ms | 6224 KB | Output is correct |
18 | Correct | 1 ms | 348 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 0 ms | 348 KB | Output is correct |
2 | Correct | 1 ms | 348 KB | Output is correct |
3 | Correct | 1 ms | 348 KB | Output is correct |
4 | Correct | 1 ms | 348 KB | Output is correct |
5 | Correct | 4 ms | 348 KB | Output is correct |
6 | Correct | 12 ms | 468 KB | Output is correct |
7 | Correct | 60 ms | 680 KB | Output is correct |
8 | Correct | 1 ms | 348 KB | Output is correct |
9 | Correct | 5 ms | 344 KB | Output is correct |
10 | Correct | 5 ms | 348 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 0 ms | 348 KB | Output is correct |
2 | Correct | 1 ms | 348 KB | Output is correct |
3 | Correct | 1 ms | 476 KB | Output is correct |
4 | Correct | 1 ms | 348 KB | Output is correct |
5 | Correct | 4 ms | 348 KB | Output is correct |
6 | Correct | 12 ms | 468 KB | Output is correct |
7 | Correct | 60 ms | 680 KB | Output is correct |
8 | Correct | 1 ms | 348 KB | Output is correct |
9 | Correct | 5 ms | 344 KB | Output is correct |
10 | Correct | 5 ms | 348 KB | Output is correct |
11 | Correct | 1 ms | 348 KB | Output is correct |
12 | Runtime error | 104 ms | 262144 KB | Execution killed with signal 9 |
13 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 0 ms | 348 KB | Output is correct |
2 | Correct | 1 ms | 348 KB | Output is correct |
3 | Correct | 1 ms | 476 KB | Output is correct |
4 | Correct | 1 ms | 348 KB | Output is correct |
5 | Correct | 4 ms | 348 KB | Output is correct |
6 | Correct | 12 ms | 468 KB | Output is correct |
7 | Correct | 60 ms | 680 KB | Output is correct |
8 | Correct | 1 ms | 348 KB | Output is correct |
9 | Correct | 5 ms | 344 KB | Output is correct |
10 | Correct | 5 ms | 348 KB | Output is correct |
11 | Correct | 6 ms | 1116 KB | Output is correct |
12 | Correct | 12 ms | 1880 KB | Output is correct |
13 | Correct | 36 ms | 5588 KB | Output is correct |
14 | Correct | 74 ms | 11216 KB | Output is correct |
15 | Correct | 58 ms | 9228 KB | Output is correct |
16 | Correct | 56 ms | 8568 KB | Output is correct |
17 | Correct | 55 ms | 6228 KB | Output is correct |
18 | Correct | 48 ms | 6228 KB | Output is correct |
19 | Correct | 18 ms | 3100 KB | Output is correct |
20 | Correct | 51 ms | 6748 KB | Output is correct |
21 | Correct | 70 ms | 10892 KB | Output is correct |
22 | Correct | 76 ms | 9232 KB | Output is correct |
23 | Correct | 59 ms | 8528 KB | Output is correct |
24 | Correct | 53 ms | 6224 KB | Output is correct |
25 | Runtime error | 104 ms | 262144 KB | Execution killed with signal 9 |
26 | Halted | 0 ms | 0 KB | - |