結果

問題 No.45 回転寿司
ユーザー nanatutmcnanatutmc
提出日時 2019-10-30 00:55:46
言語 C
(gcc 12.3.0)
結果
RE  
実行時間 -
コード長 1,131 bytes
コンパイル時間 148 ms
コンパイル使用メモリ 28,604 KB
実行使用メモリ 4,356 KB
最終ジャッジ日時 2023-10-12 23:35:22
合計ジャッジ時間 1,545 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 RE -
testcase_01 RE -
testcase_02 RE -
testcase_03 RE -
testcase_04 RE -
testcase_05 RE -
testcase_06 RE -
testcase_07 RE -
testcase_08 RE -
testcase_09 RE -
testcase_10 RE -
testcase_11 RE -
testcase_12 RE -
testcase_13 RE -
testcase_14 RE -
testcase_15 RE -
testcase_16 RE -
testcase_17 RE -
testcase_18 RE -
testcase_19 RE -
testcase_20 RE -
testcase_21 RE -
testcase_22 RE -
testcase_23 RE -
testcase_24 RE -
testcase_25 RE -
testcase_26 RE -
testcase_27 RE -
testcase_28 RE -
testcase_29 RE -
testcase_30 RE -
testcase_31 RE -
testcase_32 RE -
testcase_33 RE -
権限があれば一括ダウンロードができます
コンパイルメッセージ
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)
        return V[0];
    
    if (N == 2) {
        if (V[0] > V[1])
            return V[0];
        else
            return V[1];
    }
    
    int s1, s2;
    s1 = takeSushi(0, 0, N, V);
    s2 = takeSushi(0, 1, N, V);
    if (s1 > s2)
        return s1;
    else
        return 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