結果

問題 No.78 クジ付きアイスバー
ユーザー 👑 はまやんはまやんはまやんはまやん
提出日時 2015-06-25 00:16:52
言語 Java21
(openjdk 21)
結果
AC  
実行時間 135 ms / 5,000 ms
コード長 1,488 bytes
コンパイル時間 2,089 ms
コンパイル使用メモリ 77,216 KB
実行使用メモリ 54,424 KB
最終ジャッジ日時 2024-04-25 13:35:29
合計ジャッジ時間 8,273 ms
ジャッジサーバーID
(参考情報)
judge2 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 127 ms
54,064 KB
testcase_01 AC 130 ms
53,864 KB
testcase_02 AC 129 ms
54,212 KB
testcase_03 AC 128 ms
54,100 KB
testcase_04 AC 117 ms
52,804 KB
testcase_05 AC 135 ms
54,248 KB
testcase_06 AC 130 ms
53,856 KB
testcase_07 AC 131 ms
53,976 KB
testcase_08 AC 126 ms
53,840 KB
testcase_09 AC 128 ms
53,948 KB
testcase_10 AC 128 ms
54,240 KB
testcase_11 AC 127 ms
54,064 KB
testcase_12 AC 130 ms
54,080 KB
testcase_13 AC 130 ms
54,060 KB
testcase_14 AC 127 ms
53,872 KB
testcase_15 AC 127 ms
54,156 KB
testcase_16 AC 130 ms
54,424 KB
testcase_17 AC 127 ms
54,128 KB
testcase_18 AC 130 ms
54,196 KB
testcase_19 AC 129 ms
54,044 KB
testcase_20 AC 130 ms
54,152 KB
testcase_21 AC 130 ms
54,120 KB
testcase_22 AC 132 ms
54,244 KB
testcase_23 AC 115 ms
52,720 KB
testcase_24 AC 129 ms
54,216 KB
testcase_25 AC 131 ms
53,972 KB
testcase_26 AC 132 ms
54,120 KB
testcase_27 AC 130 ms
54,200 KB
testcase_28 AC 128 ms
53,936 KB
testcase_29 AC 125 ms
52,956 KB
testcase_30 AC 130 ms
54,112 KB
testcase_31 AC 132 ms
54,012 KB
testcase_32 AC 130 ms
54,004 KB
testcase_33 AC 129 ms
54,168 KB
testcase_34 AC 131 ms
54,072 KB
testcase_35 AC 130 ms
54,200 KB
testcase_36 AC 128 ms
53,868 KB
testcase_37 AC 129 ms
54,148 KB
testcase_38 AC 126 ms
54,028 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.ArrayList;
import java.util.HashSet;
import java.util.Scanner;


public class Main {
	static int N, K;
	static String S;
			
	static private void solve()
	{
		// 一周分測定する
		int buybar = 0;
		int nextbar = 0;
		int freebar = 0;
		
		for (int k = 0; k < N; k++) {
			if (freebar > 0) 
				freebar--;
			else 
				buybar++;
			
			switch (S.charAt(k)) {
			case '0': break;
			case '1': freebar++;  break;
			case '2': freebar+=2; break;
			}
			
			if((k+1) == K)
			{
				System.out.println(buybar);
				return;
			}
		}
		
		// 一周するときに
		int loopbuy = buybar;
		int loopfree = freebar;
		
		if(loopbuy <= loopfree)
		{
			System.out.println(loopbuy);
			return;
		}
		
		buybar = 0;
		nextbar = 0;
		freebar = 0;
		
		int loop = K/N;
		
		int k = loop * N;
		freebar = loopfree;
		buybar = loopbuy + (loopbuy - loopfree) * (loop - 1);
		
		/*for (int i = 0; i < loop; i++) {
			if(freebar >= loopbuy)
			{
				freebar -= loopbuy;
			}
			else {
				buybar += loopbuy - freebar;
				freebar = 0;
			}
			
			freebar += loopfree;
		}*/
		for (; k < K; k++) {
			if (freebar > 0) 
				freebar--;
			else 
				buybar++;
			
			switch (S.charAt(k%N)) {
			case '0': break;
			case '1': freebar++;  break;
			case '2': freebar+=2; break;
			}
		}
		
		System.out.println(buybar);
	}
	
	static public void main(String[] args)
	{
		Scanner sca = new Scanner(System.in);
		
		N = sca.nextInt();
		K = sca.nextInt();
		S = sca.next();
		
		solve();
	}
}
0