結果

問題 No.78 クジ付きアイスバー
ユーザー mitsuomitsuo
提出日時 2016-05-07 18:52:23
言語 Java21
(openjdk 21)
結果
AC  
実行時間 135 ms / 5,000 ms
コード長 1,937 bytes
コンパイル時間 2,463 ms
コンパイル使用メモリ 79,268 KB
実行使用メモリ 54,304 KB
最終ジャッジ日時 2024-04-25 14:47:49
合計ジャッジ時間 8,778 ms
ジャッジサーバーID
(参考情報)
judge3 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 128 ms
53,932 KB
testcase_01 AC 125 ms
54,184 KB
testcase_02 AC 129 ms
53,876 KB
testcase_03 AC 127 ms
54,168 KB
testcase_04 AC 127 ms
54,024 KB
testcase_05 AC 128 ms
54,248 KB
testcase_06 AC 126 ms
54,104 KB
testcase_07 AC 128 ms
54,136 KB
testcase_08 AC 134 ms
54,136 KB
testcase_09 AC 129 ms
54,200 KB
testcase_10 AC 126 ms
54,232 KB
testcase_11 AC 127 ms
54,032 KB
testcase_12 AC 129 ms
54,136 KB
testcase_13 AC 131 ms
54,148 KB
testcase_14 AC 129 ms
54,160 KB
testcase_15 AC 130 ms
54,244 KB
testcase_16 AC 130 ms
54,084 KB
testcase_17 AC 128 ms
54,024 KB
testcase_18 AC 129 ms
54,260 KB
testcase_19 AC 130 ms
54,224 KB
testcase_20 AC 129 ms
53,988 KB
testcase_21 AC 128 ms
53,952 KB
testcase_22 AC 130 ms
54,004 KB
testcase_23 AC 128 ms
54,304 KB
testcase_24 AC 130 ms
54,160 KB
testcase_25 AC 129 ms
54,208 KB
testcase_26 AC 130 ms
53,988 KB
testcase_27 AC 129 ms
54,264 KB
testcase_28 AC 129 ms
54,240 KB
testcase_29 AC 135 ms
54,268 KB
testcase_30 AC 127 ms
54,128 KB
testcase_31 AC 130 ms
54,132 KB
testcase_32 AC 130 ms
54,200 KB
testcase_33 AC 131 ms
54,140 KB
testcase_34 AC 129 ms
54,072 KB
testcase_35 AC 131 ms
54,064 KB
testcase_36 AC 129 ms
53,832 KB
testcase_37 AC 129 ms
54,016 KB
testcase_38 AC 129 ms
53,988 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

package jp.fedom.challange.yuki.l2.q78;

import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		List<String> input = new ArrayList<>();
		while (sc.hasNext()) {
			input.add(sc.nextLine());
		}

		System.out.println(solve(input));

		sc.close();
	}

	public static long solve_slow(List<String> in) {
		int N = Integer.valueOf(in.get(0).split(" ")[0]);
		long K = Long.valueOf(in.get(0).split(" ")[1]);
		int[] ice = new int[N];
		int iceTotal = 0;
		for (int i = 0; i < in.get(1).length(); i++) {
			ice[i] = Integer.valueOf(in.get(1).substring(i, i + 1));
			iceTotal += ice[i];
		}

		long p = 0;
		int stock = 0;
		for (long i = 0; i < K; i++) {
			if (i == N) {
				if (iceTotal >= N) {
					break;
				}
			}

			if (stock == 0) {
				p++;
			} else {
				stock--;
			}

			int r = ice[(int) (i % N)];
			if (r != 0) {
				stock += r;
			}

		}

		return p;
	}

	public static long solve(List<String> in) {
		int N = Integer.valueOf(in.get(0).split(" ")[0]);
		long K = Long.valueOf(in.get(0).split(" ")[1]);
		int[] ice = new int[N];
		int iceTotal = 0;
		for (int i = 0; i < in.get(1).length(); i++) {
			ice[i] = Integer.valueOf(in.get(1).substring(i, i + 1));
			iceTotal += ice[i];
		}

		long p = 0;
		int stock = 0;
		for (long i = 0; i < K; i++) {
			if (i == N) {
				if (iceTotal >= N) {
					break;
				} else if (iceTotal < N) {
					int diff = N - iceTotal;
					// System.out.println(p + " " + i + " " + diff);
					if ((K / N) - 2 > 0) {
						long skip = (K / N) - 2;
						p += skip * diff;
						i += skip * N;
					}
					// System.out.println(p + " " + i);
				}
			}
			// System.out.println("pis " + p + " " + i + " " + stock);

			if (stock == 0) {
				p++;
			} else {
				stock--;
			}

			int r = ice[(int) (i % N)];
			if (r != 0) {
				stock += r;
			}

		}

		return p;
	}

}
0