提出 #17915750
ソースコード 拡げる
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
constexpr int Inf = 1000000030;
constexpr ll INF= 2000000000000000000;
constexpr ll MOD = 998244353;
const double PI = 3.1415926535897;
typedef pair<int,int> P;
typedef pair<int,P> PP;
template<class T> inline bool chmax(T &a, T b) {
if (a < b) {
a = b;
return 1;
}
return 0;
}
template<class T> inline bool chmin(T &a, T b) {
if (a > b) {
a = b;
return 1;
}
return 0;
}
ll mod(ll val, ll M) {
val = val % M;
if(val < 0) {
val += M;
}
return val;
}
template<typename T>
T RS(T N, T P, T M){
if(P == 0) {
return 1;
}
if(P < 0) {
return 0;
}
if(P % 2 == 0){
ll t = RS(N, P/2, M);
if(M == -1) return t * t;
return t * t % M;
}
if(M == -1) {
return N * RS(N,P - 1,M);
}
return N * RS(N, P-1, M) % M;
}
int N;
ll vec[4010];
ll dp[4010][4010];
ll solve(int i,int j) {
if(i > j) return 0;
if(dp[i][j] != -1) return dp[i][j];
if((N - (j - i + 1)) % 2 == 0) {
return dp[i][j] = max(solve(i + 1,j) + vec[i],solve(i,j - 1) + vec[j]);
}
else {
if(vec[i] > vec[j]) return dp[i][j] = solve(i + 1,j);
return dp[i][j] = solve(i,j - 1);
}
}
int main() {
cin >> N;
for(int i = 0;i < N;i++) {
int A;
cin >> A;
vec[i] = A;
vec[i + N] = A;
}
for(int i = 0;i < 4010;i++) {
for(int j = 0;j < 4010;j++) {
dp[i][j] = -1;
}
}
ll ret = 0;
for(int i = 0;i < N;i++) {
chmax(ret,solve(i,i + N - 1));
}
cout << ret << endl;
}
提出情報
| 提出日時 | |
|---|---|
| 問題 | B - ケーキの切り分け2 (Cake 2) |
| ユーザ | AItale |
| 言語 | C++ (GCC 9.2.1) |
| 得点 | 100 |
| コード長 | 1771 Byte |
| 結果 | AC |
| 実行時間 | 160 ms |
| メモリ | 129420 KiB |
ジャッジ結果
| セット名 | Subtask01 | Subtask02 | Subtask03 | ||||||
|---|---|---|---|---|---|---|---|---|---|
| 得点 / 配点 | 15 / 15 | 45 / 45 | 40 / 40 | ||||||
| 結果 |
|
|
|
| セット名 | テストケース |
|---|---|
| Subtask01 | sample-01.txt, sample-02.txt, sample-03.txt, 01-01.txt, 01-02.txt, 01-03.txt, 01-04.txt, 01-05.txt, 01-06.txt, 01-07.txt, 01-08.txt, 01-09.txt, 01-10.txt |
| Subtask02 | sample-01.txt, sample-02.txt, sample-03.txt, 01-01.txt, 01-02.txt, 01-03.txt, 01-04.txt, 01-05.txt, 01-06.txt, 01-07.txt, 01-08.txt, 01-09.txt, 01-10.txt, 02-01.txt, 02-02.txt, 02-03.txt, 02-04.txt, 02-05.txt, 02-06.txt, 02-07.txt, 02-08.txt, 02-09.txt, 02-10.txt |
| Subtask03 | sample-01.txt, sample-02.txt, sample-03.txt, 01-01.txt, 01-02.txt, 01-03.txt, 01-04.txt, 01-05.txt, 01-06.txt, 01-07.txt, 01-08.txt, 01-09.txt, 01-10.txt, 02-01.txt, 02-02.txt, 02-03.txt, 02-04.txt, 02-05.txt, 02-06.txt, 02-07.txt, 02-08.txt, 02-09.txt, 02-10.txt, 03-01.txt, 03-02.txt, 03-03.txt, 03-04.txt, 03-05.txt, 03-06.txt, 03-07.txt, 03-08.txt, 03-09.txt, 03-10.txt |
| ケース名 | 結果 | 実行時間 | メモリ |
|---|---|---|---|
| 01-01.txt | AC | 84 ms | 128996 KiB |
| 01-02.txt | AC | 81 ms | 129204 KiB |
| 01-03.txt | AC | 80 ms | 129208 KiB |
| 01-04.txt | AC | 79 ms | 129136 KiB |
| 01-05.txt | AC | 80 ms | 129200 KiB |
| 01-06.txt | AC | 79 ms | 129180 KiB |
| 01-07.txt | AC | 80 ms | 129192 KiB |
| 01-08.txt | AC | 77 ms | 129048 KiB |
| 01-09.txt | AC | 82 ms | 129236 KiB |
| 01-10.txt | AC | 81 ms | 129040 KiB |
| 02-01.txt | AC | 81 ms | 129140 KiB |
| 02-02.txt | AC | 79 ms | 129000 KiB |
| 02-03.txt | AC | 78 ms | 129148 KiB |
| 02-04.txt | AC | 81 ms | 129156 KiB |
| 02-05.txt | AC | 80 ms | 129260 KiB |
| 02-06.txt | AC | 81 ms | 129064 KiB |
| 02-07.txt | AC | 82 ms | 129192 KiB |
| 02-08.txt | AC | 83 ms | 129068 KiB |
| 02-09.txt | AC | 80 ms | 129256 KiB |
| 02-10.txt | AC | 83 ms | 129260 KiB |
| 03-01.txt | AC | 85 ms | 129088 KiB |
| 03-02.txt | AC | 99 ms | 129088 KiB |
| 03-03.txt | AC | 159 ms | 129388 KiB |
| 03-04.txt | AC | 100 ms | 129216 KiB |
| 03-05.txt | AC | 159 ms | 129356 KiB |
| 03-06.txt | AC | 159 ms | 129420 KiB |
| 03-07.txt | AC | 160 ms | 129232 KiB |
| 03-08.txt | AC | 160 ms | 129384 KiB |
| 03-09.txt | AC | 156 ms | 129360 KiB |
| 03-10.txt | AC | 160 ms | 129184 KiB |
| sample-01.txt | AC | 82 ms | 129128 KiB |
| sample-02.txt | AC | 79 ms | 129176 KiB |
| sample-03.txt | AC | 80 ms | 128996 KiB |