結果
| 問題 |
No.2064 Smallest Sequence on Grid
|
| コンテスト | |
| ユーザー |
umezo
|
| 提出日時 | 2022-09-03 19:44:56 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 2,232 ms / 3,000 ms |
| コード長 | 1,052 bytes |
| コンパイル時間 | 1,961 ms |
| コンパイル使用メモリ | 205,176 KB |
| 最終ジャッジ日時 | 2025-02-07 02:28:53 |
|
ジャッジサーバーID (参考情報) |
judge2 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 2 |
| other | AC * 29 |
ソースコード
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define ALL(v) v.begin(),v.end()
typedef long long ll;
#include<bits/stdc++.h>
using namespace std;
using pii=pair<int,int>;
int main(){
ios::sync_with_stdio(false);
std::cin.tie(nullptr);
int h,w;
cin>>h>>w;
vector<string> S(h);
rep(i,h) cin>>S[i];
vector<char> ans(h+w-1);
ans[0]=S[0][0];
set<pii> se;
se.insert({0,0});
for(int k=1;k<h+w-1;k++){
char tmp='|';
rep(i,h){
int j=k-i;
if(j<0 || j>=w) continue;
bool b=false;
if(i>0 && se.count({i-1,j})) b=true;
if(j>0 && se.count({i,j-1})) b=true;
if(b==false) continue;
tmp=min(tmp,S[i][j]);
}
ans[k]=tmp;
set<pii> se2;
rep(i,h){
int j=k-i;
if(j<0 || j>=w) continue;
if(S[i][j]!=tmp) continue;
bool b=false;
if(i>0 && se.count({i-1,j})) b=true;
if(j>0 && se.count({i,j-1})) b=true;
if(b==false) continue;
se2.insert({i,j});
}
swap(se,se2);
}
rep(i,h+w-1) cout<<ans[i];
cout<<endl;
return 0;
}
umezo