제출 #854722

#제출 시각아이디문제언어결과실행 시간메모리
854722QuangBuiCigle (COI21_cigle)C++14
48 / 100
1029 ms10172 KiB
// QuangBuiCP #ifndef LOCAL #pragma GCC optimize(3) #pragma GCC target("avx2") #endif // LOCAL #include "bits/stdc++.h" using namespace std; #define SZ(a) (int)(a).size() #define ALL(a) (a).begin(),(a).end() const int N = 5005; int n; int a[N]; int pref[N]; int dp[N][N]; int Brute() { int ret = 0; for (int mask = 0; mask < (1 << n); ++mask) { int cnt = 0; set<int> prv, cur; int pos = 0, layer = 0; bool no = false; for (int i = 1; i < n; ++i) { int x1 = 0, x2 = 0; if (mask >> i & 1) { x1 = 1; } if (mask >> (i - 1) & 1) { x2 = 1; } if (x1 && x2) { no = true; break; } } if (no) { continue; } for (int i = 0; i < n; ++i) { if (mask >> i & 1) { layer++; prv = cur; cur.clear(); } int sign = 1; if (layer % 2) { sign *= -1; } pos += sign * a[i + 1]; if (prv.count(pos) && i != n - 1 && !(mask >> (i + 1) & 1)) { cnt++; } cur.insert(pos); } ret = max(ret, cnt); } return ret; } signed main() { #ifndef LOCAL cin.tie(nullptr)->sync_with_stdio(false); #endif // LOCAL cin >> n; for (int i = 1; i <= n; ++i) { cin >> a[i]; } // if (n <= 20) { // cout << Brute() << '\n'; // return 0; // } for (int l = 1; l <= n; ++l) { for (int r = l; r <= n; ++r) { int s = 0, sr = 0; int pos = l; int cnt = 0; for (int i = l - 1; i >= 1; --i) { s += a[i]; while (pos < r && s > sr) { sr += a[pos++]; } dp[l][r] = max(dp[l][r], dp[i][l - 1] + cnt); if (s == sr) { cnt++; } } } } int ans = 0; for (int i = 1; i <= n; ++i) { ans = max(ans, dp[i][n]); } cout << ans << '\n'; #ifdef LOCAL cerr << '\n' << clock() << "ms."; #endif // LOCAL 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...