結果
| 問題 |
No.2064 Smallest Sequence on Grid
|
| コンテスト | |
| ユーザー |
houren
|
| 提出日時 | 2022-09-02 21:48:31 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 915 ms / 3,000 ms |
| コード長 | 1,180 bytes |
| コンパイル時間 | 2,105 ms |
| コンパイル使用メモリ | 185,400 KB |
| 実行使用メモリ | 14,336 KB |
| 最終ジャッジ日時 | 2024-11-16 03:02:17 |
| 合計ジャッジ時間 | 10,870 ms |
|
ジャッジサーバーID (参考情報) |
judge3 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 2 |
| other | AC * 29 |
ソースコード
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<ll,ll>;
using T = tuple<int,int,int>;
#define fix(x) fixed << setprecision(x)
#define asc(x) x, vector<x>, greater<x>
#define rep(i, n) for(ll i = 0; i < n; i++)
#define all(x) (x).begin(),(x).end()
template<class T>bool chmin(T&a, const T&b){if(a>b){a=b;return 1;}return 0;}
template<class T>bool chmax(T&a, const T&b){if(a<b){a=b;return 1;}return 0;}
int main(){
cin.tie(nullptr);
ios::sync_with_stdio(false);
int h,w;
cin >> h >> w;
vector<int> ans(h+w-1,1001001001);
vector<string> s(h);
rep(i,h) cin >> s[i];
priority_queue<asc(T)> pq;
pq.push({0,s[0][0],0});
vector<vector<bool>> seen(h,vector<bool>(w,false));
seen[0][0] = true;
while(pq.size()){
int p,x,q;
tie(p,x,q) = pq.top();
pq.pop();
if(ans[p]<x) continue;
ans[p] = x;
p -= q;
if(p!=h-1 && !seen[p+1][q]) {pq.push({p+q+1,s[p+1][q],q}); seen[p+1][q] = true;}
if(q!=w-1 && !seen[p][q+1]) {pq.push({p+q+1,s[p][q+1],q+1}); seen[p][q+1] = true;}
}
rep(i,h+w-1) cout << (char)ans[i];
cout << '\n';
return 0;
}
houren