結果
問題 | No.2064 Smallest Sequence on Grid |
ユーザー | Nzt3 |
提出日時 | 2022-09-02 21:40:47 |
言語 | C++17(gcc12) (gcc 12.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 623 ms / 3,000 ms |
コード長 | 950 bytes |
コンパイル時間 | 2,822 ms |
コンパイル使用メモリ | 222,084 KB |
実行使用メモリ | 13,824 KB |
最終ジャッジ日時 | 2024-11-16 02:50:06 |
合計ジャッジ時間 | 9,153 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 2 |
other | AC * 29 |
ソースコード
#include<bits/stdc++.h> using namespace std; int main(){ ios::sync_with_stdio(false); cin.tie(nullptr); int H,W; cin>>H>>W; vector<vector<char>>A(H,vector<char>(W)); for(int i=0;i<H;i++){ for(int j=0;j<W;j++)cin>>A[i][j]; } queue<array<int,2>>bfs; bfs.push({0,0}); string ans=""; ans+=A[0][0]; vector<vector<bool>>vst(H,vector<bool>(W)); while(bfs.size()){ int s=bfs.size(); vector<pair<char,array<int,2>>>v; for(int i=0;i<s;i++){ int x=bfs.front()[0],y=bfs.front()[1]; bfs.pop(); if(x+1<H&&!vst[x+1][y]){ v.push_back({A[x+1][y],{x+1,y}}); vst[x+1][y]=true; } if(y+1<W&&!vst[x][y+1]){ v.push_back({A[x][y+1],{x,y+1}}); vst[x][y+1]=true; } } sort(v.begin(),v.end()); if(v.empty())break; char c=v[0].first; ans+=c; for(auto i:v){ if(i.first==c){ bfs.push(i.second); } } } cout<<ans<<'\n'; }