結果

問題 No.540 格子点と経路
ユーザー 37zigen37zigen
提出日時 2017-07-01 06:57:50
言語 Java21
(openjdk 21)
結果
WA  
実行時間 -
コード長 867 bytes
コンパイル時間 2,607 ms
コンパイル使用メモリ 77,916 KB
実行使用メモリ 54,656 KB
最終ジャッジ日時 2024-04-15 09:50:09
合計ジャッジ時間 8,025 ms
ジャッジサーバーID
(参考情報)
judge3 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 163 ms
54,112 KB
testcase_01 AC 163 ms
54,204 KB
testcase_02 AC 158 ms
54,316 KB
testcase_03 AC 160 ms
54,164 KB
testcase_04 AC 154 ms
54,408 KB
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 AC 164 ms
54,112 KB
testcase_15 WA -
testcase_16 AC 169 ms
54,436 KB
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 AC 159 ms
54,516 KB
testcase_23 AC 163 ms
54,400 KB
testcase_24 WA -
権限があれば一括ダウンロードができます

ソースコード

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;
		}

		int 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