結果

問題 No.45 回転寿司
ユーザー nanatutmcnanatutmc
提出日時 2019-10-30 01:00:21
言語 C
(gcc 12.3.0)
結果
RE  
実行時間 -
コード長 1,176 bytes
コンパイル時間 189 ms
コンパイル使用メモリ 28,552 KB
実行使用メモリ 4,372 KB
最終ジャッジ日時 2023-10-12 23:35:26
合計ジャッジ時間 1,843 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,372 KB
testcase_01 AC 1 ms
4,368 KB
testcase_02 AC 1 ms
4,368 KB
testcase_03 AC 1 ms
4,368 KB
testcase_04 AC 1 ms
4,368 KB
testcase_05 AC 1 ms
4,368 KB
testcase_06 AC 1 ms
4,372 KB
testcase_07 AC 1 ms
4,372 KB
testcase_08 AC 0 ms
4,372 KB
testcase_09 AC 1 ms
4,372 KB
testcase_10 AC 0 ms
4,368 KB
testcase_11 AC 1 ms
4,372 KB
testcase_12 AC 1 ms
4,372 KB
testcase_13 AC 0 ms
4,368 KB
testcase_14 AC 0 ms
4,368 KB
testcase_15 AC 0 ms
4,368 KB
testcase_16 AC 1 ms
4,372 KB
testcase_17 AC 1 ms
4,372 KB
testcase_18 AC 1 ms
4,372 KB
testcase_19 AC 1 ms
4,372 KB
testcase_20 AC 0 ms
4,372 KB
testcase_21 AC 1 ms
4,368 KB
testcase_22 AC 0 ms
4,368 KB
testcase_23 AC 0 ms
4,368 KB
testcase_24 AC 1 ms
4,368 KB
testcase_25 RE -
testcase_26 AC 1 ms
4,368 KB
testcase_27 AC 1 ms
4,368 KB
testcase_28 AC 1 ms
4,368 KB
testcase_29 AC 1 ms
4,368 KB
testcase_30 AC 1 ms
4,368 KB
testcase_31 AC 1 ms
4,368 KB
testcase_32 WA -
testcase_33 AC 1 ms
4,368 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.c: 関数 ‘main’ 内:
main.c:28:10: 警告: 関数 ‘takeSushi’ の暗黙的な宣言です [-Wimplicit-function-declaration]
   28 |     s1 = takeSushi(0, 0, N, V);
      |          ^~~~~~~~~

ソースコード

diff #

#include <stdio.h>

int scoreTable[1000];

int main() {
    int N;
    int V[1000];
    
    scanf("%d", &N);
    
    int i;
    for (int i=0; i<N; i++) {
        scanf("%d", &(V[i]));
        scoreTable[i] = 0;
    }
    
    if (N == 1)
        printf("%d\n", V[0]);
    
    if (N == 2) {
        if (V[0] > V[1])
            printf("%d\n", V[0]);
        else
            printf("%d\n", V[1]);
    }
    
    int s1, s2;
    s1 = takeSushi(0, 0, N, V);
    s2 = takeSushi(0, 1, N, V);
    if (s1 > s2)
        printf("%d\n", s1);
    else
        printf("%d\n", s2);
}

int takeSushi(int score, int position, int N, int V[]) {
    if (scoreTable[position] > 0)
        return score+scoreTable[position];

    int score1 = score + V[position];
    
    if (position == N-1 || position == N-2) {
        return score1;
    }
    
    if (position == N-3) {
        return score1 + V[N-1];
    }
    
    int s1, s2;
    s1 = takeSushi(score1, position+2, N, V);
    s2 = takeSushi(score1, position+3, N, V);
    
    if (s1 > s2) {
        scoreTable[position] = s1-score;
        return s1;
    } else {
        scoreTable[position] = s2-score;
        return s2;
    }
}
0