Submission #760926

#TimeUsernameProblemLanguageResultExecution timeMemory
760926usuyusCigle (COI21_cigle)C++17
100 / 100
204 ms98440 KiB
#include <bits/stdc++.h> using namespace std; using ll = long long; int main() { ios_base::sync_with_stdio(false); cin.tie(nullptr); int n; cin >> n; vector<int> bricks(n); for (int &x : bricks) cin >> x; vector dp(n+1, vector(n+1, 0)); for (int i = 0; i <= n; i++) { for (int j = 1; j < i; j++) { dp[j][i] = max(dp[j][i], dp[j-1][i]); } int balance = 0; int matches = 0; int current = 0; for (int k = i+1, j = i; k <= n; k++) { balance += bricks[k-1]; while (j > 0 && balance - bricks[j-1] >= 0) { balance -= bricks[--j]; } dp[i][k] = max(dp[i][k-1], current); if (balance == 0) { matches++; if (j > 0) current = max(current, dp[j-1][i] + matches); } } } cout << dp[n-1][n] << endl; }
#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...