結果

問題 No.78 クジ付きアイスバー
ユーザー uafr_csuafr_cs
提出日時 2015-06-17 01:19:17
言語 Java21
(openjdk 21)
結果
WA  
実行時間 -
コード長 1,131 bytes
コンパイル時間 2,286 ms
コンパイル使用メモリ 78,744 KB
実行使用メモリ 41,672 KB
最終ジャッジ日時 2024-04-16 05:01:32
合計ジャッジ時間 8,228 ms
ジャッジサーバーID
(参考情報)
judge5 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 AC 128 ms
41,216 KB
testcase_02 AC 118 ms
40,088 KB
testcase_03 AC 128 ms
41,344 KB
testcase_04 WA -
testcase_05 AC 130 ms
41,224 KB
testcase_06 AC 130 ms
41,348 KB
testcase_07 AC 129 ms
41,304 KB
testcase_08 AC 130 ms
41,216 KB
testcase_09 AC 122 ms
40,952 KB
testcase_10 AC 129 ms
41,672 KB
testcase_11 AC 119 ms
40,288 KB
testcase_12 AC 126 ms
41,296 KB
testcase_13 AC 128 ms
41,316 KB
testcase_14 AC 129 ms
41,228 KB
testcase_15 AC 128 ms
41,036 KB
testcase_16 AC 116 ms
39,964 KB
testcase_17 AC 127 ms
41,388 KB
testcase_18 AC 116 ms
40,208 KB
testcase_19 WA -
testcase_20 AC 129 ms
41,188 KB
testcase_21 AC 133 ms
41,232 KB
testcase_22 WA -
testcase_23 AC 128 ms
41,236 KB
testcase_24 AC 127 ms
41,144 KB
testcase_25 AC 119 ms
40,448 KB
testcase_26 WA -
testcase_27 WA -
testcase_28 WA -
testcase_29 AC 130 ms
41,252 KB
testcase_30 WA -
testcase_31 WA -
testcase_32 WA -
testcase_33 WA -
testcase_34 WA -
testcase_35 WA -
testcase_36 WA -
testcase_37 AC 131 ms
41,624 KB
testcase_38 AC 128 ms
41,264 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.math.BigDecimal;
import java.util.Arrays;
import java.util.Scanner;

public class Main {
	
	public static long simulate(final int N, int[] S, long K, final long initial_bonus){
		long bonus = initial_bonus;
		long cost = 0;
		
		for(long i = 0; i < K; i++){
			final int index = (int)(i % N);
			
			if(bonus > 0){
				bonus--;
			}else{
				cost++;
			}
			
			bonus += S[index];
		}
		
		return cost;
	}
	
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		
		final int N = sc.nextInt();
		final long K = sc.nextLong();
		
		char[] inputs = sc.next().toCharArray();
		int[] S = new int[N];
		for(int i = 0; i < N; i++){ S[i] = Character.getNumericValue(inputs[i]); }
		
		int one_cycle_cost = 0, one_cycle_bonus = 0;
		for(int i = 0; i < N; i++){
			if(one_cycle_bonus > 0){
				one_cycle_bonus--;
			}else{
				one_cycle_cost++;
			}
			
			one_cycle_bonus += S[i];
		}
		
		if(one_cycle_bonus > 0){
			if(one_cycle_bonus >= one_cycle_cost){
				System.out.println(one_cycle_cost);
			}
			
		}else{
			System.out.println((K / N * one_cycle_cost) + simulate(N, S, K % N, 0));
		}	
	}
}
0