結果
問題 | No.2064 Smallest Sequence on Grid |
ユーザー | okkuukenken |
提出日時 | 2022-09-02 21:36:15 |
言語 | C++23 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 1,353 ms / 3,000 ms |
コード長 | 993 bytes |
コンパイル時間 | 2,087 ms |
コンパイル使用メモリ | 157,500 KB |
実行使用メモリ | 15,104 KB |
最終ジャッジ日時 | 2024-11-16 02:37:09 |
合計ジャッジ時間 | 13,320 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 2 |
other | AC * 29 |
ソースコード
#define _USE_MATH_DEFINES #include<iostream> #include<vector> #include<algorithm> #include<cmath> #include<string> #include<iomanip> #include<numeric> #include<queue> #include<deque> #include<stack> #include<set> #include<map> #include<random> #include<bitset> #include<cassert> #include<complex> #include<fstream> #include<cstdlib> #include<functional> #include<array> using namespace std; typedef long long ll; const int mod=998244353; int main(){ int h,w; string s[3000]; cin>>h>>w; for(int i=0;i<h;i++) cin>>s[i]; string ans={s[0][0]}; set<pair<int,int>>tmp={{0,0}}; for(int i=0;i<h+w-2;i++){ set<pair<int,int>>nxt; char c=-1; for(auto[x,y]:tmp){ if(x!=h-1){ if(c==-1||c>s[x+1][y]){ c=s[x+1][y]; nxt.clear(); } if(c==s[x+1][y]) nxt.insert({x+1,y}); } if(y!=w-1){ if(c==-1||c>s[x][y+1]){ c=s[x][y+1]; nxt.clear(); } if(c==s[x][y+1]) nxt.insert({x,y+1}); } } ans+=c; tmp.swap(nxt); } cout<<ans<<endl; }