結果
| 問題 |
No.2064 Smallest Sequence on Grid
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2022-09-02 22:22:11 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 955 ms / 3,000 ms |
| コード長 | 1,085 bytes |
| コンパイル時間 | 2,317 ms |
| コンパイル使用メモリ | 207,168 KB |
| 最終ジャッジ日時 | 2025-02-07 01:29:11 |
|
ジャッジサーバーID (参考情報) |
judge3 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 2 |
| other | AC * 29 |
ソースコード
#include <bits/stdc++.h>
using namespace std;
using P = pair<int, int>;
int main () {
int H, W;
cin >> H >> W;
char A[3030][3030];
for (int i = 0; i < H; i ++) {
for (int j = 0; j < W; j ++) {
cin >> A[i][j];
}
}
for (int i = 0; i < H; i ++) {
A[i][W] = '{';
}
for (int j = 0; j < W; j ++) {
A[H][j] = '{';
}
vector<P> now = {P{0, 0}};
cout << A[0][0];
string key = "abcdefghijklmnopqrstuvwxyz";
for (int i = 2; i < H + W; i ++) {
std::vector<P> X[50];
for (auto [x, y] : now) {
X[A[x + 1][y] - 'a'].emplace_back(x + 1, y);
X[A[x][y + 1] - 'a'].emplace_back(x, y + 1);
}
int fl = 0;
while (X[fl].empty()) {
fl ++;
}
cout << key[fl];
now.clear();
sort(X[fl].begin(), X[fl].end());
auto result = std::unique(X[fl].begin(), X[fl].end());
X[fl].erase(result, X[fl].end());
for (auto x : X[fl]) {
now.push_back(x);
}
}
cout << endl;
}