結果

問題 No.2064 Smallest Sequence on Grid
ユーザー 沙耶花沙耶花
提出日時 2022-09-02 21:28:50
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 630 ms / 3,000 ms
コード長 1,013 bytes
コンパイル時間 5,110 ms
コンパイル使用メモリ 268,176 KB
実行使用メモリ 15,284 KB
最終ジャッジ日時 2023-08-10 03:21:18
合計ジャッジ時間 12,943 ms
ジャッジサーバーID
(参考情報)
judge15 / judge14
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 2 ms
4,380 KB
testcase_03 AC 2 ms
4,376 KB
testcase_04 AC 1 ms
4,380 KB
testcase_05 AC 2 ms
4,376 KB
testcase_06 AC 2 ms
4,380 KB
testcase_07 AC 2 ms
4,380 KB
testcase_08 AC 2 ms
4,380 KB
testcase_09 AC 2 ms
4,376 KB
testcase_10 AC 2 ms
4,380 KB
testcase_11 AC 2 ms
4,376 KB
testcase_12 AC 2 ms
4,376 KB
testcase_13 AC 2 ms
4,380 KB
testcase_14 AC 2 ms
4,380 KB
testcase_15 AC 2 ms
4,376 KB
testcase_16 AC 2 ms
4,376 KB
testcase_17 AC 163 ms
14,784 KB
testcase_18 AC 162 ms
14,792 KB
testcase_19 AC 162 ms
15,132 KB
testcase_20 AC 488 ms
14,924 KB
testcase_21 AC 522 ms
15,108 KB
testcase_22 AC 390 ms
15,256 KB
testcase_23 AC 401 ms
14,992 KB
testcase_24 AC 397 ms
14,980 KB
testcase_25 AC 399 ms
15,176 KB
testcase_26 AC 630 ms
14,996 KB
testcase_27 AC 630 ms
15,020 KB
testcase_28 AC 163 ms
14,744 KB
testcase_29 AC 527 ms
15,284 KB
testcase_30 AC 149 ms
14,092 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#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;
}
0