結果

問題 No.540 格子点と経路
ユーザー 37zigen37zigen
提出日時 2017-07-01 06:41:44
言語 Java21
(openjdk 21)
結果
AC  
実行時間 147 ms / 2,000 ms
コード長 772 bytes
コンパイル時間 2,321 ms
コンパイル使用メモリ 75,376 KB
実行使用メモリ 57,276 KB
最終ジャッジ日時 2024-04-15 09:49:08
合計ジャッジ時間 6,922 ms
ジャッジサーバーID
(参考情報)
judge2 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 140 ms
54,008 KB
testcase_01 AC 139 ms
54,348 KB
testcase_02 AC 139 ms
54,180 KB
testcase_03 AC 141 ms
54,160 KB
testcase_04 AC 137 ms
54,180 KB
testcase_05 AC 142 ms
57,040 KB
testcase_06 AC 142 ms
56,220 KB
testcase_07 AC 143 ms
57,276 KB
testcase_08 AC 145 ms
55,120 KB
testcase_09 AC 141 ms
56,024 KB
testcase_10 AC 144 ms
56,368 KB
testcase_11 AC 143 ms
54,864 KB
testcase_12 AC 147 ms
56,468 KB
testcase_13 AC 144 ms
55,188 KB
testcase_14 AC 142 ms
54,736 KB
testcase_15 AC 143 ms
55,524 KB
testcase_16 AC 141 ms
55,056 KB
testcase_17 AC 142 ms
56,568 KB
testcase_18 AC 144 ms
56,428 KB
testcase_19 AC 144 ms
54,620 KB
testcase_20 AC 142 ms
56,284 KB
testcase_21 AC 140 ms
56,252 KB
testcase_22 AC 140 ms
54,296 KB
testcase_23 AC 143 ms
54,328 KB
testcase_24 AC 147 ms
56,680 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.io.FileNotFoundException;
import java.util.Arrays;
import java.util.Scanner;

public class Main {
	public static void main(String[] args) throws FileNotFoundException {
		new Main().run();
	}

	final long MODULO = 1_000_000_000 + 7;

	void run() {
		Scanner sc = new Scanner(System.in);
		int w = sc.nextInt();
		int h = sc.nextInt();
		int m = Math.min(w, h);
		int M = Math.max(w, h);
		System.out.println(f(m, M));
	}

	long f(int m, int M) {
		if (m > M) {
			int d = M;
			M = m;
			m = d;
		}
		if (m == 0 && M == 0) {
			return 0;
		}
		if (m == 0 && M > 0) {
			return 1;
		}
		if (m == 1) {
			return 2 * M + 1;
		}
		return 2 * (m + M - 1) + f(m - 2, M - 2);
	}

	void tr(Object... objects) {
		System.out.println(Arrays.deepToString(objects));
	}
}
0