結果

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

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 115 ms
56,024 KB
testcase_01 AC 115 ms
55,736 KB
testcase_02 AC 118 ms
55,700 KB
testcase_03 AC 117 ms
55,548 KB
testcase_04 AC 116 ms
56,192 KB
testcase_05 AC 116 ms
55,788 KB
testcase_06 AC 115 ms
55,840 KB
testcase_07 AC 115 ms
56,100 KB
testcase_08 AC 119 ms
55,640 KB
testcase_09 AC 117 ms
55,792 KB
testcase_10 AC 117 ms
56,060 KB
testcase_11 AC 119 ms
55,884 KB
testcase_12 AC 116 ms
55,912 KB
testcase_13 AC 120 ms
55,876 KB
testcase_14 AC 119 ms
55,764 KB
testcase_15 AC 118 ms
56,372 KB
testcase_16 AC 120 ms
55,416 KB
testcase_17 AC 123 ms
55,888 KB
testcase_18 AC 119 ms
56,044 KB
testcase_19 AC 121 ms
55,488 KB
testcase_20 AC 116 ms
56,088 KB
testcase_21 AC 117 ms
55,760 KB
testcase_22 AC 116 ms
55,672 KB
testcase_23 AC 118 ms
55,628 KB
testcase_24 AC 120 ms
55,864 KB
testcase_25 AC 119 ms
55,496 KB
testcase_26 AC 121 ms
55,724 KB
testcase_27 AC 118 ms
55,508 KB
testcase_28 AC 117 ms
55,724 KB
testcase_29 AC 115 ms
55,792 KB
testcase_30 AC 117 ms
55,412 KB
testcase_31 AC 116 ms
55,864 KB
testcase_32 AC 117 ms
55,976 KB
testcase_33 AC 116 ms
55,876 KB
testcase_34 AC 116 ms
55,704 KB
testcase_35 AC 122 ms
56,116 KB
testcase_36 AC 119 ms
55,648 KB
testcase_37 AC 118 ms
55,868 KB
testcase_38 AC 116 ms
55,620 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());
		long k=Long.parseLong(scanner.next());
		String s=scanner.next();
		long[][] nx=new long[32][51];
		final long INF=(long)1e12;
		for(int i=0; i<n; i++) {
			int sum=0;
			for(int j=i; j<i+n; j++) {
				int x=s.charAt(j%n)-'0';
				sum+=x;
				if(sum+1==j-i+1) {
					nx[0][i]=j+1;
					break;
				}
			}
			if(nx[0][i]==0) {
				nx[0][i]=INF;
			}
		}
		for(int i=1; i<=30; i++) {
			for(int j=0; j<n; j++) {
				long x=nx[i-1][j];
				if(x==INF) {
					nx[i][j]=INF;
				}else{
					nx[i][j]=Math.min(INF, x/n*n+nx[i-1][(int) (x%n)]);
				}
			}
		}
		long ans=0;
		int x=0;
		for(int i=30; i>=0; i--) {
			if(nx[i][x]<k) {
				ans+=(1<<i);
				k-=nx[i][x]/n*n;
				x=(int)(nx[i][x]%n);
			}
		}
		out.println(ans+1);
		out.close();
		scanner.close();
	}
}
0