Submission #501455

#TimeUsernameProblemLanguageResultExecution timeMemory
501455MazaalaiBigger segments (IZhO19_segments)C++17
37 / 100
273 ms71040 KiB
#include <bits/stdc++.h> using namespace std; using ll = long long; using VI = vector <int>; using VLL = vector <ll>; int n, m; const int N = 3e3 + 5; const ll INF = 1e18; ll ans = 1; ll nums[N], pre[N], dp[N][N]; signed main () { ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); // freopen("in.txt", "r", stdin); // freopen("out.txt", "w", stdout); cin >> n; for (int i = 1; i <= n; i++) cin >> nums[i]; for (int i = 1; i <= n; i++) pre[i] += pre[i-1] + nums[i]; for (int i = 0; i <= n; i++) for (int j = 0; j <= n; j++) dp[i][j] = INF; dp[1][1] = nums[1]; ll sum = 0; int m = n+1; for (int i = 1; i < n; i++) for (int j = 1; j <= n; j++) { dp[i][j] = min(dp[i][j], dp[i][j-1]+nums[j]); ll tar = dp[i][j] + pre[j]; int id = lower_bound(pre, pre + m, tar) - pre; if (id <= n && pre[id] >= tar) { dp[i+1][id] = min(dp[i+1][id], pre[id] - pre[j]); ans = i+1; } } // for (int i = 1; i <= n; i++) // for (int j = 1; j <= n; j++) cout << (dp[i][j] == INF ? -1 : dp[i][j]) << " \n"[j==n]; cout << ans << '\n'; }

Compilation message (stderr)

segments.cpp: In function 'int main()':
segments.cpp:23:5: warning: unused variable 'sum' [-Wunused-variable]
   23 |  ll sum = 0;
      |     ^~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...