結果

問題 No.45 回転寿司
ユーザー shota525shota525
提出日時 2018-05-03 20:55:44
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 586 ms / 5,000 ms
コード長 851 bytes
コンパイル時間 1,207 ms
コンパイル使用メモリ 143,480 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-08-27 16:25:21
合計ジャッジ時間 6,505 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 19 ms
4,376 KB
testcase_01 AC 140 ms
4,380 KB
testcase_02 AC 349 ms
4,380 KB
testcase_03 AC 533 ms
4,376 KB
testcase_04 AC 159 ms
4,380 KB
testcase_05 AC 2 ms
4,376 KB
testcase_06 AC 36 ms
4,376 KB
testcase_07 AC 346 ms
4,380 KB
testcase_08 AC 11 ms
4,376 KB
testcase_09 AC 303 ms
4,380 KB
testcase_10 AC 32 ms
4,376 KB
testcase_11 AC 7 ms
4,376 KB
testcase_12 AC 247 ms
4,376 KB
testcase_13 AC 2 ms
4,380 KB
testcase_14 AC 1 ms
4,380 KB
testcase_15 AC 33 ms
4,376 KB
testcase_16 AC 12 ms
4,376 KB
testcase_17 AC 28 ms
4,380 KB
testcase_18 AC 19 ms
4,380 KB
testcase_19 AC 295 ms
4,376 KB
testcase_20 AC 2 ms
4,380 KB
testcase_21 AC 2 ms
4,376 KB
testcase_22 AC 1 ms
4,380 KB
testcase_23 AC 1 ms
4,376 KB
testcase_24 AC 1 ms
4,376 KB
testcase_25 AC 1 ms
4,380 KB
testcase_26 AC 43 ms
4,376 KB
testcase_27 AC 239 ms
4,376 KB
testcase_28 AC 47 ms
4,376 KB
testcase_29 AC 285 ms
4,376 KB
testcase_30 AC 268 ms
4,380 KB
testcase_31 AC 2 ms
4,380 KB
testcase_32 AC 2 ms
4,376 KB
testcase_33 AC 586 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>

using namespace std;

int N;
int taste[1000] = {0};
int dp[1001] = {0};
int result = 0;

void rec(int number = 0, int sum = 0){
    
    if(number == (N - 1) || number == (N - 2)){
        if(result < sum) result = sum;
        if(sum == 0) result = taste[number];
        return;
    }
    
    if(dp[number] != 0 && dp[number] >= sum) return;
    dp[number] = sum;
    
    int i;
    if(number == 0 && sum == 0){
        for(i = 0; i < N; ++i){
            rec(i, sum + taste[i]);
        }
    }
    else{
        for(i = number + 1; i < N; ++i){
            if(i != (number + 1)) rec(i, sum + taste[i]);
        }
    }
    
    return;
}

int main(void){
    
    cin >> N;
    
    int i;
    for(i = 0; i < N; ++i){
        cin >> taste[i];
    }
    
    rec();
    
    cout << result << endl;
    
    return 0;
}
0