結果

問題 No.78 クジ付きアイスバー
ユーザー GrenacheGrenache
提出日時 2015-11-06 20:13:31
言語 Java21
(openjdk 21)
結果
AC  
実行時間 124 ms / 5,000 ms
コード長 951 bytes
コンパイル時間 3,047 ms
コンパイル使用メモリ 77,836 KB
実行使用メモリ 54,448 KB
最終ジャッジ日時 2024-04-25 14:37:13
合計ジャッジ時間 8,659 ms
ジャッジサーバーID
(参考情報)
judge1 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 113 ms
53,324 KB
testcase_01 AC 118 ms
52,984 KB
testcase_02 AC 106 ms
53,160 KB
testcase_03 AC 111 ms
53,676 KB
testcase_04 AC 107 ms
52,760 KB
testcase_05 AC 106 ms
52,996 KB
testcase_06 AC 112 ms
53,692 KB
testcase_07 AC 118 ms
54,056 KB
testcase_08 AC 117 ms
54,448 KB
testcase_09 AC 119 ms
54,220 KB
testcase_10 AC 119 ms
54,264 KB
testcase_11 AC 117 ms
54,036 KB
testcase_12 AC 118 ms
53,872 KB
testcase_13 AC 122 ms
54,044 KB
testcase_14 AC 110 ms
53,456 KB
testcase_15 AC 116 ms
54,060 KB
testcase_16 AC 111 ms
53,664 KB
testcase_17 AC 105 ms
52,824 KB
testcase_18 AC 118 ms
53,624 KB
testcase_19 AC 109 ms
52,816 KB
testcase_20 AC 106 ms
52,856 KB
testcase_21 AC 118 ms
54,184 KB
testcase_22 AC 120 ms
54,112 KB
testcase_23 AC 109 ms
53,040 KB
testcase_24 AC 121 ms
54,172 KB
testcase_25 AC 108 ms
53,244 KB
testcase_26 AC 117 ms
54,000 KB
testcase_27 AC 116 ms
54,412 KB
testcase_28 AC 111 ms
53,232 KB
testcase_29 AC 106 ms
52,760 KB
testcase_30 AC 121 ms
53,856 KB
testcase_31 AC 124 ms
54,036 KB
testcase_32 AC 124 ms
53,952 KB
testcase_33 AC 109 ms
53,100 KB
testcase_34 AC 124 ms
54,400 KB
testcase_35 AC 116 ms
54,116 KB
testcase_36 AC 117 ms
54,264 KB
testcase_37 AC 117 ms
54,084 KB
testcase_38 AC 111 ms
52,836 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.Scanner;


public class Main_yukicoder78 {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);

        int n = sc.nextInt();
        int k = sc.nextInt();
        char[] s = sc.next().toCharArray();
        int[] a = new int[n + 1];
        int[] min = new int[n + 1];

        for (int i = 1; i <= n; i++) {
        	if (a[i - 1] > 0) {
        		min[i] = min[i - 1];
        		a[i] = a[i - 1] - 1 + s[i - 1] - '0';
        	} else {
        		min[i] = min[i - 1] + 1;
        		a[i] = a[i - 1] + s[i - 1] - '0';
        	}
        }
        
        if (k > n && a[n] >= min[n]) {
        	System.out.println(min[n]);
        } else if (k <= n) {
        	System.out.println(min[k]);
        } else {
        	long ret = (min[n] - a[n]) * (k / n - 1);
        	ret += min[n] + Math.max(0, min[k % n] - a[n]);
        	
        	System.out.println(ret);
        }

        sc.close();
    }
}
0