ログインしてください。
提出 #534856
ソースコード 拡げる
#include<iostream>
#include<algorithm>
using namespace std;
int main(){
int n;
cin >> n;
long a[n], b[n];
for (int i = 0; i < n; i++) {
cin >> a[i];
}
for (int i = 0; i < n; i++) {
cin >> b[i];
}
long dp[n][n+1];
for (int i = 0; i < n; i++) {
for (int j = 0; j <= n; j++) {
dp[i][j] = -1;
}
}
int x, y;
if (a[0] < 0 && b[0] <= 0) {
cout << 0 << endl;
}else{
long dp[2][n+1];
for (int i = 0; i < 2; i++) {
for (int j = 0; j < n+1; j++) {
dp[i][j] = -1;
}
}
dp[0][0] = b[0];
dp[0][1] = a[0];
long ans = max(dp[0][0], dp[0][1]);
for (int i = 1; i < n; i++) {
for (int j = 0; j <= i+1; j++) {
if (j == 0) {
dp[i%2][0] = dp[(i-1)%2][0]+b[0];
}else{
if (dp[(i-1)%2][j-1]<0 && dp[(i-1)%2][j] < 0) {
dp[i%2][j] = -1;
}else if(dp[(i-1)%2][j-1]<0){
dp[i%2][j] =dp[(i-1)%2][j]+b[j];
}else if(dp[(i-1)%2][j] < 0){
dp[i%2][j] = dp[(i-1)%2][j-1]+a[j-1];
}else{
dp[i%2][j] = max(dp[(i-1)%2][j-1]+a[j-1], dp[(i-1)%2][j]+b[j]);
}
}
ans = max(ans, dp[i%2][j]);
}
if (ans < 0) {
break;
}
}
if (ans <= 0) {
cout << 0 << endl;
}else{
cout << ans << endl;
}
}
return 0;
}
提出情報
| 提出日時 | |
|---|---|
| 問題 | D - 高橋君の旅行 |
| ユーザ | taijin |
| 言語 | C++ (GCC 4.9.2) |
| 得点 | 3 |
| コード長 | 1719 Byte |
| 結果 | RE |
| 実行時間 | 443 ms |
| メモリ | 2532 KiB |
ジャッジ結果
| セット名 | Small | All | ||||||
|---|---|---|---|---|---|---|---|---|
| 得点 / 配点 | 3 / 3 | 0 / 197 | ||||||
| 結果 |
|
|
| セット名 | テストケース |
|---|---|
| Small | 00_small_sample_00.txt, 00_small_sample_01.txt, 00_small_sample_02.txt, 00_small_sample_03.txt, 10_small_01.txt, 10_small_02.txt, 10_small_03.txt, 10_small_04.txt, 10_small_05.txt, 10_small_06.txt, 90_small_teuchi_00.txt, 90_small_teuchi_01.txt, 90_small_teuchi_02.txt |
| All | 00_small_sample_00.txt, 00_small_sample_01.txt, 00_small_sample_02.txt, 00_small_sample_03.txt, 10_small_01.txt, 10_small_02.txt, 10_small_03.txt, 10_small_04.txt, 10_small_05.txt, 10_small_06.txt, 20_large_01.txt, 20_large_02.txt, 20_large_03.txt, 20_large_04.txt, 20_large_05.txt, 20_large_06.txt, 20_large_07.txt, 20_large_08.txt, 20_large_09.txt, 20_large_10.txt, 20_large_11.txt, 20_large_12.txt, 20_large_13.txt, 20_large_14.txt, 20_large_15.txt, 20_large_16.txt, 20_large_17.txt, 20_large_18.txt, 20_large_19.txt, 20_large_20.txt, 20_large_21.txt, 20_large_22.txt, 20_large_23.txt, 20_large_24.txt, 20_large_25.txt, 20_large_26.txt, 20_large_27.txt, 20_large_28.txt, 20_large_29.txt, 20_large_30.txt, 30_run_through_01.txt, 70_maximum_01.txt, 80_hand_01.txt, 80_hand_02.txt, 80_hand_03.txt, 80_hand_04.txt, 90_small_teuchi_00.txt, 90_small_teuchi_01.txt, 90_small_teuchi_02.txt |
| ケース名 | 結果 | 実行時間 | メモリ |
|---|---|---|---|
| 00_small_sample_00.txt | AC | 32 ms | 932 KiB |
| 00_small_sample_01.txt | AC | 27 ms | 912 KiB |
| 00_small_sample_02.txt | AC | 27 ms | 860 KiB |
| 00_small_sample_03.txt | AC | 24 ms | 920 KiB |
| 10_small_01.txt | AC | 27 ms | 860 KiB |
| 10_small_02.txt | AC | 25 ms | 868 KiB |
| 10_small_03.txt | AC | 24 ms | 864 KiB |
| 10_small_04.txt | AC | 24 ms | 872 KiB |
| 10_small_05.txt | AC | 25 ms | 1052 KiB |
| 10_small_06.txt | AC | 24 ms | 860 KiB |
| 20_large_01.txt | RE | 400 ms | 2348 KiB |
| 20_large_02.txt | RE | 429 ms | 2404 KiB |
| 20_large_03.txt | RE | 424 ms | 2532 KiB |
| 20_large_04.txt | RE | 422 ms | 2452 KiB |
| 20_large_05.txt | RE | 443 ms | 2368 KiB |
| 20_large_06.txt | RE | 425 ms | 2348 KiB |
| 20_large_07.txt | RE | 437 ms | 2340 KiB |
| 20_large_08.txt | RE | 421 ms | 2364 KiB |
| 20_large_09.txt | RE | 424 ms | 2396 KiB |
| 20_large_10.txt | RE | 398 ms | 2364 KiB |
| 20_large_11.txt | RE | 424 ms | 2364 KiB |
| 20_large_12.txt | RE | 420 ms | 2348 KiB |
| 20_large_13.txt | RE | 391 ms | 2364 KiB |
| 20_large_14.txt | RE | 401 ms | 2528 KiB |
| 20_large_15.txt | RE | 400 ms | 2396 KiB |
| 20_large_16.txt | RE | 385 ms | 2404 KiB |
| 20_large_17.txt | RE | 398 ms | 2404 KiB |
| 20_large_18.txt | RE | 398 ms | 2444 KiB |
| 20_large_19.txt | RE | 405 ms | 2368 KiB |
| 20_large_20.txt | RE | 418 ms | 2408 KiB |
| 20_large_21.txt | RE | 424 ms | 2364 KiB |
| 20_large_22.txt | RE | 383 ms | 2528 KiB |
| 20_large_23.txt | RE | 402 ms | 2408 KiB |
| 20_large_24.txt | RE | 395 ms | 2524 KiB |
| 20_large_25.txt | RE | 399 ms | 2412 KiB |
| 20_large_26.txt | RE | 423 ms | 2368 KiB |
| 20_large_27.txt | RE | 418 ms | 2368 KiB |
| 20_large_28.txt | RE | 403 ms | 2364 KiB |
| 20_large_29.txt | RE | 422 ms | 2368 KiB |
| 20_large_30.txt | RE | 418 ms | 2412 KiB |
| 30_run_through_01.txt | RE | 417 ms | 2396 KiB |
| 70_maximum_01.txt | RE | 431 ms | 2404 KiB |
| 80_hand_01.txt | RE | 337 ms | 2412 KiB |
| 80_hand_02.txt | RE | 343 ms | 2524 KiB |
| 80_hand_03.txt | RE | 337 ms | 2368 KiB |
| 80_hand_04.txt | RE | 336 ms | 2364 KiB |
| 90_small_teuchi_00.txt | AC | 28 ms | 916 KiB |
| 90_small_teuchi_01.txt | AC | 27 ms | 1044 KiB |
| 90_small_teuchi_02.txt | AC | 28 ms | 948 KiB |