結果

問題 No.47 ポケットを叩くとビスケットが2倍
ユーザー oyafusooyafuso
提出日時 2019-03-15 14:48:08
言語 Java21
(openjdk 21)
結果
AC  
実行時間 128 ms / 5,000 ms
コード長 988 bytes
コンパイル時間 2,251 ms
コンパイル使用メモリ 72,720 KB
実行使用メモリ 56,292 KB
最終ジャッジ日時 2023-09-14 12:16:11
合計ジャッジ時間 6,503 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 124 ms
56,172 KB
testcase_01 AC 123 ms
56,044 KB
testcase_02 AC 123 ms
55,840 KB
testcase_03 AC 123 ms
55,684 KB
testcase_04 AC 122 ms
54,388 KB
testcase_05 AC 122 ms
55,764 KB
testcase_06 AC 123 ms
56,236 KB
testcase_07 AC 123 ms
55,776 KB
testcase_08 AC 122 ms
55,524 KB
testcase_09 AC 121 ms
56,292 KB
testcase_10 AC 122 ms
55,984 KB
testcase_11 AC 122 ms
55,828 KB
testcase_12 AC 123 ms
55,872 KB
testcase_13 AC 122 ms
55,876 KB
testcase_14 AC 124 ms
55,968 KB
testcase_15 AC 125 ms
55,912 KB
testcase_16 AC 120 ms
56,144 KB
testcase_17 AC 122 ms
55,824 KB
testcase_18 AC 122 ms
56,164 KB
testcase_19 AC 128 ms
55,712 KB
testcase_20 AC 124 ms
55,628 KB
testcase_21 AC 125 ms
55,680 KB
testcase_22 AC 124 ms
53,752 KB
testcase_23 AC 125 ms
55,728 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.*;

class Main {

	private static final String SPLIT_STR = " ";

	public static void main(String[] args) {
		// Scanner生成
		Scanner sc = new Scanner(System.in);
		// 入力設定
		String input = sc.nextLine();
		String[] split = input.split(SPLIT_STR);
		List<Integer> numList = new ArrayList<>(split.length);
		for (int i = 0; i < split.length; i++) {
			numList.add(Integer.parseInt(split[i]));
		}
		// Scannerクローズ
		sc.close();

		/* メイン処理開始 */
		// 変数初期化
		int result = 0;
		int N = numList.get(0);
		// 結果設定
		result = count(1, N);
		/* メイン処理終了 */

		// 結果出力
		System.out.println(result);
	}

	private static int count(int beginNum, int endNum) {
		int result = 0;
		int total = beginNum;
		int add = 1;
		while (total < endNum) {
			if ((total + add) > endNum ) {
				add = (int)Math.ceil(endNum - total);
			} else {
				total += add;
				add += add;
				result++;
			}
		}
		return result;
	}
}
0