結果

問題 No.2064 Smallest Sequence on Grid
ユーザー 沙耶花沙耶花
提出日時 2022-09-02 21:28:50
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 615 ms / 3,000 ms
コード長 1,013 bytes
コンパイル時間 4,772 ms
コンパイル使用メモリ 271,776 KB
実行使用メモリ 15,232 KB
最終ジャッジ日時 2024-04-27 20:54:31
合計ジャッジ時間 10,601 ms
ジャッジサーバーID
(参考情報)
judge2 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
6,816 KB
testcase_01 AC 2 ms
6,940 KB
testcase_02 AC 2 ms
6,940 KB
testcase_03 AC 2 ms
6,940 KB
testcase_04 AC 2 ms
6,944 KB
testcase_05 AC 2 ms
6,944 KB
testcase_06 AC 2 ms
6,944 KB
testcase_07 AC 1 ms
6,940 KB
testcase_08 AC 2 ms
6,940 KB
testcase_09 AC 2 ms
6,940 KB
testcase_10 AC 1 ms
6,944 KB
testcase_11 AC 2 ms
6,940 KB
testcase_12 AC 2 ms
6,940 KB
testcase_13 AC 1 ms
6,940 KB
testcase_14 AC 1 ms
6,940 KB
testcase_15 AC 2 ms
6,940 KB
testcase_16 AC 2 ms
6,944 KB
testcase_17 AC 161 ms
14,720 KB
testcase_18 AC 164 ms
14,976 KB
testcase_19 AC 155 ms
14,848 KB
testcase_20 AC 463 ms
15,232 KB
testcase_21 AC 504 ms
15,104 KB
testcase_22 AC 378 ms
15,104 KB
testcase_23 AC 384 ms
15,232 KB
testcase_24 AC 387 ms
14,976 KB
testcase_25 AC 373 ms
15,232 KB
testcase_26 AC 615 ms
15,232 KB
testcase_27 AC 592 ms
15,232 KB
testcase_28 AC 161 ms
14,976 KB
testcase_29 AC 494 ms
15,232 KB
testcase_30 AC 149 ms
14,336 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