結果
| 問題 |
No.2064 Smallest Sequence on Grid
|
| コンテスト | |
| ユーザー |
NAMIDAIRO
|
| 提出日時 | 2022-09-02 21:51:26 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 495 ms / 3,000 ms |
| コード長 | 1,388 bytes |
| コンパイル時間 | 1,223 ms |
| コンパイル使用メモリ | 106,988 KB |
| 実行使用メモリ | 16,256 KB |
| 最終ジャッジ日時 | 2024-11-16 03:10:40 |
| 合計ジャッジ時間 | 7,461 ms |
|
ジャッジサーバーID (参考情報) |
judge3 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 2 |
| other | AC * 29 |
ソースコード
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <queue>
#include <set>
#include <random>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (n); i++)
template<class T>
using vi = vector<T>;
template<class T>
using vii = vector<vi<T>>;
template<class T>
using viii = vector<vii<T>>;
using pii = pair<int, int>;
struct status {
int x, y;
};
int main()
{
int h, w;
cin >> h >> w;
vi<string> s(h);
rep(i, h) cin >> s[i];
queue<status> q;
q.push({ 0, 0 });
char c = s[0][0];
cout << c;
vii<bool> visited(h, vi<bool>(w));
const int dx[2] = { 1, 0 };
const int dy[2] = { 0, 1 };
for (int sm = 0; sm < h + w - 2; sm++) {
char nc = 'z';
while (!q.empty() && q.front().x + q.front().y == sm) {
status v = q.front();
q.pop();
if (s[v.x][v.y] != c) continue;
if (visited[v.x][v.y]) continue;
visited[v.x][v.y] = true;
rep(i, 2) {
int nx = v.x + dx[i];
int ny = v.y + dy[i];
if (nx >= h || ny >= w) continue;
if (s[nx][ny] <= nc) {
q.push({ nx, ny });
nc = s[nx][ny];
}
}
}
c = nc;
cout << c;
}
cout << endl;
return 0;
}
NAMIDAIRO