結果
問題 | No.2064 Smallest Sequence on Grid |
ユーザー | qqspeed20015 |
提出日時 | 2022-09-02 22:03:24 |
言語 | C++14 (gcc 12.3.0 + boost 1.83.0) |
結果 |
MLE
|
実行時間 | - |
コード長 | 1,116 bytes |
コンパイル時間 | 2,032 ms |
コンパイル使用メモリ | 182,140 KB |
実行使用メモリ | 814,464 KB |
最終ジャッジ日時 | 2024-04-27 21:37:41 |
合計ジャッジ時間 | 4,680 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge4 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 2 ms
6,812 KB |
testcase_01 | AC | 1 ms
6,944 KB |
testcase_02 | AC | 2 ms
6,944 KB |
testcase_03 | AC | 2 ms
6,944 KB |
testcase_04 | AC | 1 ms
6,940 KB |
testcase_05 | AC | 2 ms
6,944 KB |
testcase_06 | AC | 1 ms
6,944 KB |
testcase_07 | AC | 1 ms
6,944 KB |
testcase_08 | AC | 2 ms
6,940 KB |
testcase_09 | AC | 2 ms
6,940 KB |
testcase_10 | AC | 4 ms
6,940 KB |
testcase_11 | AC | 3 ms
6,940 KB |
testcase_12 | AC | 3 ms
6,940 KB |
testcase_13 | AC | 4 ms
6,940 KB |
testcase_14 | AC | 4 ms
6,940 KB |
testcase_15 | AC | 3 ms
6,944 KB |
testcase_16 | AC | 4 ms
6,944 KB |
testcase_17 | MLE | - |
testcase_18 | -- | - |
testcase_19 | -- | - |
testcase_20 | -- | - |
testcase_21 | -- | - |
testcase_22 | -- | - |
testcase_23 | -- | - |
testcase_24 | -- | - |
testcase_25 | -- | - |
testcase_26 | -- | - |
testcase_27 | -- | - |
testcase_28 | -- | - |
testcase_29 | -- | - |
testcase_30 | -- | - |
ソースコード
#include <bits/stdc++.h> using namespace std; vector <vector <bool>> isVisited; vector <string> listMatrix; vector <vector <string>> dp; int H, W; string solve(int i, int j) { string ans; if (i == H - 1 && j == W - 1) { ans = listMatrix[i][j]; return ans; } if (isVisited[i][j]) return dp[i][j]; if (i == H - 1) ans = listMatrix[i][j] + solve(i, j + 1); else if (j == W - 1) ans = listMatrix[i][j] + solve(i + 1, j); else { string ans1 = solve(i, j + 1); string ans2 = solve(i + 1, j); if (ans1.compare(ans2) <= 0) ans = listMatrix[i][j] + ans1; else ans = listMatrix[i][j] + ans2; } isVisited[i][j] = true; return dp[i][j] = ans; } int main() { string str; scanf("%d %d", &H, &W); for (int i = 0; i < H; i++) { cin >> str; cin.ignore(); listMatrix.push_back(str); } isVisited = vector <vector <bool>> (H, vector <bool> (W, false)); dp = vector <vector <string>> (H, vector <string> (W)); cout << solve(0, 0); return 0; }