結果

問題 No.540 格子点と経路
ユーザー 37zigen37zigen
提出日時 2017-07-01 06:59:25
言語 Java21
(openjdk 21)
結果
AC  
実行時間 136 ms / 2,000 ms
コード長 871 bytes
コンパイル時間 2,145 ms
コンパイル使用メモリ 77,800 KB
実行使用メモリ 54,400 KB
最終ジャッジ日時 2024-04-15 08:13:21
合計ジャッジ時間 6,341 ms
ジャッジサーバーID
(参考情報)
judge2 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 130 ms
54,188 KB
testcase_01 AC 131 ms
54,320 KB
testcase_02 AC 128 ms
54,384 KB
testcase_03 AC 133 ms
53,956 KB
testcase_04 AC 136 ms
54,096 KB
testcase_05 AC 134 ms
54,400 KB
testcase_06 AC 135 ms
54,244 KB
testcase_07 AC 132 ms
54,348 KB
testcase_08 AC 132 ms
54,312 KB
testcase_09 AC 133 ms
53,780 KB
testcase_10 AC 131 ms
54,220 KB
testcase_11 AC 132 ms
54,168 KB
testcase_12 AC 132 ms
53,996 KB
testcase_13 AC 131 ms
54,160 KB
testcase_14 AC 132 ms
54,384 KB
testcase_15 AC 130 ms
54,068 KB
testcase_16 AC 130 ms
53,876 KB
testcase_17 AC 133 ms
54,112 KB
testcase_18 AC 132 ms
54,020 KB
testcase_19 AC 132 ms
53,976 KB
testcase_20 AC 135 ms
53,900 KB
testcase_21 AC 132 ms
54,200 KB
testcase_22 AC 128 ms
53,980 KB
testcase_23 AC 129 ms
54,240 KB
testcase_24 AC 133 ms
54,160 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(long m, long M) {
		if (m > M) {
			long 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;
		}

		long l = m / 2;
		return 2 * (M + m - 1) * l + f(m - 2 * l, M - 2 * l) - 4 * l * (l - 1);
//		return 2 * (m + M - 1) + f(m - 2, M - 2);
	}

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