結果
| 問題 |
No.540 格子点と経路
|
| コンテスト | |
| ユーザー |
kurenai3110
|
| 提出日時 | 2017-06-30 23:35:34 |
| 言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
| 結果 |
TLE
|
| 実行時間 | - |
| コード長 | 705 bytes |
| コンパイル時間 | 852 ms |
| コンパイル使用メモリ | 78,628 KB |
| 実行使用メモリ | 264,320 KB |
| 最終ジャッジ日時 | 2024-10-04 21:42:30 |
| 合計ジャッジ時間 | 6,554 ms |
|
ジャッジサーバーID (参考情報) |
judge1 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 TLE * 1 |
| other | AC * 1 TLE * 1 -- * 19 |
ソースコード
#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;
}
kurenai3110