結果

問題 No.1007 コイン集め
ユーザー logilogi
提出日時 2020-03-06 23:17:51
言語 C
(gcc 12.3.0)
結果
WA  
実行時間 -
コード長 1,457 bytes
コンパイル時間 549 ms
コンパイル使用メモリ 30,720 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-04-22 10:32:20
合計ジャッジ時間 1,329 ms
ジャッジサーバーID
(参考情報)
judge3 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
5,248 KB
testcase_01 AC 0 ms
5,376 KB
testcase_02 AC 1 ms
5,376 KB
testcase_03 AC 1 ms
5,376 KB
testcase_04 AC 1 ms
5,376 KB
testcase_05 AC 1 ms
5,376 KB
testcase_06 AC 1 ms
5,376 KB
testcase_07 AC 0 ms
5,376 KB
testcase_08 WA -
testcase_09 WA -
testcase_10 AC 1 ms
5,376 KB
testcase_11 AC 0 ms
5,376 KB
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 AC 9 ms
5,376 KB
testcase_16 AC 10 ms
5,376 KB
testcase_17 AC 9 ms
5,376 KB
testcase_18 WA -
testcase_19 AC 14 ms
5,376 KB
testcase_20 WA -
testcase_21 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <stdio.h>
#include <stdlib.h>

int calc_earnable_coin(int length, int* list, int start, int step);

int main(void) {
    int point_num, position;
    int *coin_count;
    int result;
    
    scanf("%d %d", &point_num, &position);
    position--;
    
    coin_count = (int*) malloc(sizeof(int)*point_num);
    
    for(int i=0; i<point_num; i++) {
        scanf("%d", &coin_count[i]);
        //printf("%d ", coin_count[i]);
    }
    
    if(coin_count[position] == 0) {
        result = 0;
    } else {
        int count_left = 0, count_right = 0;
        count_left = calc_earnable_coin(point_num, coin_count, position-1, -1);
        count_right = calc_earnable_coin(point_num, coin_count, position+1, 1);
        
        if(coin_count[position] == 1) {
            if(count_left >= count_right) {
                result = count_left + coin_count[position];
            } else {
                result = count_right + coin_count[position];
            }
        } else {
            result = count_left + count_right + coin_count[position];
        }
    }
    
    free(coin_count);
    printf("%d\n", result);
    return 0;
}

int calc_earnable_coin(int length, int* list, int start, int step) {
    int count=0;
    if(start >=  0 || start < length) {
        for(int i=start; i!=0 && i!=length; i+=step) {
            count += list[i];
            if(list[i] < 2) {
                break;
            }
        }
    }
    return count;
}
0