結果

問題 No.853 河原の石
ユーザー CuriousFairy315CuriousFairy315
提出日時 2019-07-06 01:44:27
言語 Java21
(openjdk 21)
結果
AC  
実行時間 127 ms / 3,153 ms
コード長 783 bytes
コンパイル時間 2,148 ms
コンパイル使用メモリ 77,776 KB
実行使用メモリ 57,712 KB
最終ジャッジ日時 2023-10-23 21:05:25
合計ジャッジ時間 14,273 ms
ジャッジサーバーID
(参考情報)
judge14 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 123 ms
55,464 KB
testcase_01 AC 123 ms
57,228 KB
testcase_02 AC 122 ms
57,412 KB
testcase_03 AC 124 ms
55,596 KB
testcase_04 AC 124 ms
57,288 KB
testcase_05 AC 123 ms
57,396 KB
testcase_06 AC 115 ms
56,248 KB
testcase_07 AC 122 ms
57,256 KB
testcase_08 AC 112 ms
56,244 KB
testcase_09 AC 122 ms
57,492 KB
testcase_10 AC 123 ms
57,192 KB
testcase_11 AC 123 ms
57,384 KB
testcase_12 AC 125 ms
57,712 KB
testcase_13 AC 113 ms
56,244 KB
testcase_14 AC 108 ms
55,824 KB
testcase_15 AC 123 ms
57,164 KB
testcase_16 AC 124 ms
57,324 KB
testcase_17 AC 123 ms
57,424 KB
testcase_18 AC 122 ms
57,616 KB
testcase_19 AC 124 ms
57,448 KB
testcase_20 AC 125 ms
57,508 KB
testcase_21 AC 123 ms
57,440 KB
testcase_22 AC 127 ms
57,216 KB
testcase_23 AC 125 ms
55,556 KB
testcase_24 AC 126 ms
57,532 KB
testcase_25 AC 125 ms
57,540 KB
testcase_26 AC 127 ms
57,464 KB
testcase_27 AC 127 ms
57,544 KB
testcase_28 AC 117 ms
56,204 KB
testcase_29 AC 126 ms
57,352 KB
testcase_30 AC 125 ms
57,456 KB
testcase_31 AC 124 ms
57,540 KB
testcase_32 AC 127 ms
57,188 KB
testcase_33 AC 127 ms
57,540 KB
testcase_34 AC 126 ms
57,596 KB
testcase_35 AC 125 ms
57,536 KB
testcase_36 AC 127 ms
57,240 KB
testcase_37 AC 115 ms
56,188 KB
testcase_38 AC 127 ms
57,496 KB
testcase_39 AC 126 ms
57,088 KB
testcase_40 AC 126 ms
57,556 KB
testcase_41 AC 125 ms
57,424 KB
testcase_42 AC 120 ms
57,064 KB
testcase_43 AC 123 ms
57,508 KB
testcase_44 AC 124 ms
57,584 KB
testcase_45 AC 115 ms
56,208 KB
testcase_46 AC 127 ms
57,520 KB
testcase_47 AC 116 ms
56,228 KB
testcase_48 AC 119 ms
56,200 KB
testcase_49 AC 126 ms
57,484 KB
testcase_50 AC 126 ms
57,188 KB
testcase_51 AC 126 ms
57,308 KB
testcase_52 AC 127 ms
57,364 KB
testcase_53 AC 126 ms
57,472 KB
testcase_54 AC 123 ms
57,256 KB
testcase_55 AC 122 ms
57,488 KB
testcase_56 AC 123 ms
57,524 KB
testcase_57 AC 123 ms
57,592 KB
testcase_58 AC 114 ms
56,260 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		try (Scanner sc = new Scanner(System.in)) {
			int H = sc.nextInt(), W = Math.abs(sc.nextInt());
			if (H < 0 || H > 1000000000) System.exit(1);
			else if (W > 1000000000) System.exit(1);
			if (W == 0) { // 自明な0手
				System.out.println(0);
			} else {
				long ans = H++;
				for (long i = 1, j = 1;;j += i++) {
					if (j + i <= Math.min(H, W)) {
						ans += i * i;
					} else { // 終端処理
						long dist = Math.min(H, W) - j;
						ans += i * dist;
						if (W <= H) break;
						ans += (i * i - (i - dist)) * ((W - H) / i);
						ans += i * ((W - H) % i);
						ans -= Math.min(i - dist, (W - H) % i);
						break;
					}
				}
				System.out.println(ans);
			}
		}
	}
}
0