제출 #769929

#제출 시각아이디문제언어결과실행 시간메모리
769929JomnoiBigger segments (IZhO19_segments)C++17
13 / 100
2 ms2388 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; 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...