結果

問題 No.540 格子点と経路
ユーザー kurenai3110kurenai3110
提出日時 2017-06-30 23:35:34
言語 C++11
(gcc 11.4.0)
結果
TLE  
実行時間 -
コード長 705 bytes
コンパイル時間 693 ms
コンパイル使用メモリ 78,908 KB
実行使用メモリ 258,976 KB
最終ジャッジ日時 2024-04-15 07:10:20
合計ジャッジ時間 7,096 ms
ジャッジサーバーID
(参考情報)
judge2 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
13,756 KB
testcase_01 AC 2 ms
6,940 KB
testcase_02 AC 1 ms
6,940 KB
testcase_03 TLE -
testcase_04 AC 2 ms
6,940 KB
testcase_05 TLE -
testcase_06 -- -
testcase_07 -- -
testcase_08 -- -
testcase_09 -- -
testcase_10 -- -
testcase_11 -- -
testcase_12 -- -
testcase_13 -- -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
testcase_22 -- -
testcase_23 -- -
testcase_24 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <map>
#include <queue>
#include <cstdlib>
using namespace std;

map<tuple<int, int, bool>, int>dp;

int solve(int w, int h, int dir) {
	if (dp.find(make_tuple(w, h, dir)) != dp.end())return dp[make_tuple(w, h, dir)];

	int a, b;
	a = 2 * h + 1;
	b = 2 * w + 1;

	if (dir == 1)a--;
	else b--;

	if (h == 1 || w==0)return b;
	if (w == 1 || h==0)return a;

	int ans = max(a + solve(w - 2, h,1), b + solve(w, h - 2,0));

	dp[make_tuple(w, h, dir)] = ans;

	return ans;
}

int main()
{
	int W, H; cin >> W >> H;

	if (W == 0 && H == 0)cout << 0 << endl;
	else cout << max(solve(W,H,1), solve(W, H, 0)) << endl;

	return 0;
}
0