| # | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
|---|---|---|---|---|---|---|---|
| 889041 | Hakiers | Cigle (COI21_cigle) | C++17 | 1016 ms | 21000 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
constexpr int MAXN = 5e3 + 7;
constexpr int oo = 1e9;
int dp[MAXN][MAXN][2];
int d[MAXN];
bool sum[MAXN];
int res = 0;
int n;
int compute(int j, int k, int i, bool right){
vector<int> tmp[2];
for(int z = j; z <= i; z++)
tmp[(z > k)].push_back(d[z]);
reverse(tmp[!right].begin(), tmp[!right].end());
int actsum = 0, cnt = 0;
for(int z = 0; z + 1 < tmp[0].size(); z++){
actsum += tmp[0][z];
sum[actsum] = 1;
}
actsum = 0;
for(int z = 0; z + 1 < tmp[1].size(); z++){
actsum += tmp[1][z];
if(sum[actsum]) cnt++;
}
actsum = 0;
for(int z = 0; z + 1 < tmp[0].size(); z++){
actsum += tmp[0][z];
sum[actsum] = 0;
}
return cnt;
}
void solve(){
for(int i = 0; i <= n; i++)
for(int j = 0; j <= n; j++)
dp[i][j][0] = dp[i][j][1] = -oo;
for(int i = 1; i <= n; i++)
dp[1][i][0] = 0;
for(int i = 2; i <= n; i++){
for(int k = i-1; k >= 1; k--){
for(int j = k; j >= 1; j--){
dp[k+1][i][0] = max(dp[k+1][i][0], dp[j][k][1] + compute(j, k, i, 0));
dp[k+1][i][1] = max(dp[k+1][i][1], dp[j][k][0] + compute(j, k, i, 1));
res = max({res, dp[k+1][i][0], dp[k+1][i][1]});
}
}
}
/*
for(int i = 1; i <= n; i++){
for(int k = 1; k <= n; k++){
for(int j = k-1; j <= n; j++){
for(int z = j; z < i; z++){
dp[z+1][i][k] = max(dp[z+1][i][k], dp[j][z][k-1] + compute(j, z, i, (k%2)));
res = max(res, dp[z+1][i][k]);
}
}
}
}
*/
}
int main(){
ios_base::sync_with_stdio(0);
cin.tie(0);
cin >> n;
for(int i = 1; i <= n; i++)
cin >> d[i];
solve();
cout << res << "\n";
}컴파일 시 표준 에러 (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... | ||||
