# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
420421 | Nicholas_Patrick | Cigle (COI21_cigle) | C++17 | 44 ms | 1228 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <cstdio>
#include <queue>
#include <algorithm>
using namespace std;
int n;
vector<vector<int>> dp;
int qry(int x, int y){
int ret=0;
for(int j=y; j>=0; j--)
ret=max(ret, dp[x][j]);
return ret;
}
void upd(int x, int y, int v){
for(int i=x; i<n; i++)
dp[i][y]=max(dp[i][y], v);
}
int main(){
scanf("%d", &n);
vector<int> d(n);
for(int& i : d)
scanf("%d", &i);
dp.assign(n, vector<int>(n, 0));
/*
dp[x][y]
x: last brick laid
y: earliest brick in last row
y≤x
*/
for(int i=1; i<n; i++){
vector<int> suffsum, prefsum;
for(int j=i; j--;){
if(suffsum.empty()){
suffsum.push_back(d[j]);
}else{
suffsum.push_back(d[j]+suffsum.back());
}
}
for(int j=i; j<n; j++){
if(prefsum.empty()){
prefsum.push_back(d[j]);
}else{
prefsum.push_back(d[j]+prefsum.back());
}
}
for(int j=0, k=0, matches=0; j<prefsum.size(); j++){
while(k+1<suffsum.size() and suffsum[k]<prefsum[j])
k++;
if(prefsum[j]==suffsum[k]){
matches++;
if(i+j+1<n)
upd(i+j+1, i, qry(i-1, i-k-1-1)+matches);
}
}
}
int ans=0;
for(auto& i : dp)
ans=max(ans, *max_element(i.begin(), i.end()));
printf("%d\n", ans);
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |