結果
| 問題 |
No.2064 Smallest Sequence on Grid
|
| コンテスト | |
| ユーザー |
沙耶花
|
| 提出日時 | 2022-09-02 21:28:50 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 681 ms / 3,000 ms |
| コード長 | 1,013 bytes |
| コンパイル時間 | 4,074 ms |
| コンパイル使用メモリ | 260,768 KB |
| 最終ジャッジ日時 | 2025-02-07 00:43:54 |
|
ジャッジサーバーID (参考情報) |
judge2 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 2 |
| other | AC * 29 |
ソースコード
#include <stdio.h>
#include <atcoder/all>
#include <bits/stdc++.h>
using namespace std;
using namespace atcoder;
using mint = modint998244353;
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define Inf32 1000000001
#define Inf64 4000000000000000001
int main(){
int H,W;
cin>>H>>W;
vector<string> S(H);
rep(i,H)cin>>S[i];
string ans = string(1,S[0][0]);
vector<pair<int,int>> x(1,make_pair(0,0));
rep(i,H+W-2){
vector<pair<int,int>> nx;
char c = 'z';
rep(j,x.size()){
rep(k,2){
int xx = x[j].first,yy = x[j].second;
if(k==0)xx++;
else yy++;
if(xx>=H||xx<0||yy>=W||yy<0)continue;
c = min(c,S[xx][yy]);
}
}
ans += c;
rep(j,x.size()){
rep(k,2){
int xx = x[j].first,yy = x[j].second;
if(k==0)xx++;
else yy++;
if(xx>=H||xx<0||yy>=W||yy<0)continue;
if(S[xx][yy]==c){
nx.emplace_back(xx,yy);
}
}
}
sort(nx.begin(),nx.end());
nx.erase(unique(nx.begin(),nx.end()),nx.end());
x = nx;
}
cout<<ans<<endl;
return 0;
}
沙耶花