Submission #769933

#TimeUsernameProblemLanguageResultExecution timeMemory
769933JomnoiBigger segments (IZhO19_segments)C++17
27 / 100
1569 ms66444 KiB
#include <bits/stdc++.h> using namespace std; const int MAX_N = 3005; const long long INF = 1e18 + 7; long long A[MAX_N], dp[MAX_N][MAX_N]; int main() { cin.tie(nullptr)->sync_with_stdio(false); int N; cin >> N; for (int i = 1; i <= N; i++) { cin >> A[i]; A[i] += A[i - 1]; } int ans = 1; for (int i = 1; i <= N; i++) dp[i][0] = INF; for (int i = 1; i <= N; i++) dp[1][i] = A[i]; for (int s = 2; s <= N; s++) { for (int i = 1; i <= N; i++) { dp[s][i] = INF; for (int j = i; j >= 1; j--) { if (dp[s - 1][j - 1] <= A[i] - A[j - 1]) { dp[s][i] = A[i] - A[j - 1]; break; } } // int l = 1, r = i, pos = -1; // while (l <= r) { // int mid = (l + r) / 2; // if (dp[s - 1][mid - 1] == INF) l = mid + 1; // else if (dp[s - 1][mid - 1] <= A[i] - A[mid - 1]) l = mid + 1, pos = mid; // else r = mid - 1; // } // if (pos != -1) dp[s][i] = A[i] - A[pos - 1]; } if (dp[s][N] == INF) break; ans = s; } cout << ans; return 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...