結果
| 問題 |
No.2064 Smallest Sequence on Grid
|
| コンテスト | |
| ユーザー |
umezo
|
| 提出日時 | 2022-09-02 23:01:25 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
TLE
|
| 実行時間 | - |
| コード長 | 942 bytes |
| コンパイル時間 | 2,448 ms |
| コンパイル使用メモリ | 205,792 KB |
| 最終ジャッジ日時 | 2025-02-07 01:43:48 |
|
ジャッジサーバーID (参考情報) |
judge4 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 2 |
| other | AC * 10 TLE * 19 |
ソースコード
#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 pci=pair<char,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];
string ans;
ans+=S[0][0];
queue<pair<int,int>> que;
que.push({0,0});
rep(k,h+w-2){
priority_queue<pci, vector<pci>, greater<pci>> pq;
while(que.size()){
auto c=que.front(); que.pop();
int i=c.first,j=c.second;
if(i+1<h) pq.push({S[i+1][j],{i+1,j}});
if(j+1<w) pq.push({S[i][j+1],{i,j+1}});
}
auto a=pq.top(); pq.pop();
ans+=a.first;
que.push({a.second.first,a.second.second});
while(pq.size() && pq.top().first==a.first){
auto b=pq.top(); pq.pop();
que.push({b.second.first,b.second.second});
}
}
cout<<ans<<endl;
return 0;
}
umezo