結果

問題 No.78 クジ付きアイスバー
ユーザー chocoruskchocorusk
提出日時 2020-10-03 11:20:51
言語 Java21
(openjdk 21)
結果
AC  
実行時間 123 ms / 5,000 ms
コード長 931 bytes
コンパイル時間 2,575 ms
コンパイル使用メモリ 73,760 KB
実行使用メモリ 56,376 KB
最終ジャッジ日時 2023-09-25 04:57:53
合計ジャッジ時間 8,950 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 117 ms
55,748 KB
testcase_01 AC 116 ms
55,388 KB
testcase_02 AC 119 ms
56,072 KB
testcase_03 AC 113 ms
55,444 KB
testcase_04 AC 116 ms
55,872 KB
testcase_05 AC 120 ms
56,248 KB
testcase_06 AC 120 ms
55,688 KB
testcase_07 AC 118 ms
55,524 KB
testcase_08 AC 117 ms
56,180 KB
testcase_09 AC 116 ms
55,588 KB
testcase_10 AC 120 ms
55,540 KB
testcase_11 AC 117 ms
55,708 KB
testcase_12 AC 122 ms
55,704 KB
testcase_13 AC 117 ms
55,976 KB
testcase_14 AC 120 ms
53,776 KB
testcase_15 AC 117 ms
56,376 KB
testcase_16 AC 117 ms
55,804 KB
testcase_17 AC 117 ms
55,384 KB
testcase_18 AC 117 ms
55,604 KB
testcase_19 AC 118 ms
55,828 KB
testcase_20 AC 123 ms
55,860 KB
testcase_21 AC 118 ms
55,912 KB
testcase_22 AC 117 ms
55,448 KB
testcase_23 AC 118 ms
55,648 KB
testcase_24 AC 119 ms
56,156 KB
testcase_25 AC 117 ms
55,584 KB
testcase_26 AC 118 ms
56,084 KB
testcase_27 AC 121 ms
53,816 KB
testcase_28 AC 118 ms
55,692 KB
testcase_29 AC 116 ms
55,880 KB
testcase_30 AC 117 ms
55,712 KB
testcase_31 AC 118 ms
56,016 KB
testcase_32 AC 118 ms
55,888 KB
testcase_33 AC 118 ms
55,900 KB
testcase_34 AC 120 ms
55,648 KB
testcase_35 AC 121 ms
55,708 KB
testcase_36 AC 118 ms
56,068 KB
testcase_37 AC 116 ms
55,604 KB
testcase_38 AC 119 ms
55,892 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.io.PrintWriter;
import java.util.Scanner;

public class Main{
	public static void main(String[] args) {
		Scanner scanner=new Scanner(System.in);
		PrintWriter out=new PrintWriter(System.out);
		int n=Integer.parseInt(scanner.next());
		int k=Integer.parseInt(scanner.next());
		String s=scanner.next();
		int x=0, y=0;
		int i;
		for(i=0; i<n; i++) {
			int c=s.charAt(i)-'0';
			if(y==0) {
				x++;
			}else {
				y--;
			}
			y+=c;
			if(i+1>=k) {
				out.println(x);
				out.close();
				scanner.close();
				return;
			}
		}
		if(x<=y) {
			out.println(x);
		}else {
			int ans=x+(k-n)/n*(x-y);
			k%=n;
			if(k>0) {
				int y0=y;
				x=0;
				y=0;
				for(i=0; i<n; i++) {
					int c=s.charAt(i)-'0';
					if(y==0) {
						x++;
					}else {
						y--;
					}
					y+=c;
					if(i+1>=k) {
						ans+=Math.max(0,  x-y0);
						break;
					}
				}
			}
			out.println(ans);
		}
		out.close();
		scanner.close();
	}
}
0