結果

問題 No.2064 Smallest Sequence on Grid
ユーザー okkuukenkenokkuukenken
提出日時 2022-09-02 21:36:15
言語 C++23
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 1,395 ms / 3,000 ms
コード長 993 bytes
コンパイル時間 1,419 ms
コンパイル使用メモリ 157,752 KB
実行使用メモリ 15,232 KB
最終ジャッジ日時 2024-04-27 21:04:28
合計ジャッジ時間 13,328 ms
ジャッジサーバーID
(参考情報)
judge3 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,816 KB
testcase_01 AC 2 ms
6,944 KB
testcase_02 AC 2 ms
6,940 KB
testcase_03 AC 2 ms
6,940 KB
testcase_04 AC 2 ms
6,940 KB
testcase_05 AC 2 ms
6,944 KB
testcase_06 AC 2 ms
6,940 KB
testcase_07 AC 1 ms
6,944 KB
testcase_08 AC 2 ms
6,944 KB
testcase_09 AC 2 ms
6,940 KB
testcase_10 AC 1 ms
6,940 KB
testcase_11 AC 2 ms
6,940 KB
testcase_12 AC 2 ms
6,944 KB
testcase_13 AC 2 ms
6,944 KB
testcase_14 AC 2 ms
6,944 KB
testcase_15 AC 2 ms
6,944 KB
testcase_16 AC 2 ms
6,940 KB
testcase_17 AC 166 ms
14,720 KB
testcase_18 AC 166 ms
14,848 KB
testcase_19 AC 169 ms
14,720 KB
testcase_20 AC 1,021 ms
15,104 KB
testcase_21 AC 1,096 ms
15,104 KB
testcase_22 AC 774 ms
15,104 KB
testcase_23 AC 769 ms
15,104 KB
testcase_24 AC 777 ms
15,104 KB
testcase_25 AC 778 ms
15,232 KB
testcase_26 AC 1,349 ms
15,104 KB
testcase_27 AC 1,395 ms
15,104 KB
testcase_28 AC 167 ms
14,848 KB
testcase_29 AC 1,144 ms
15,104 KB
testcase_30 AC 154 ms
14,208 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#define _USE_MATH_DEFINES
#include<iostream>
#include<vector>
#include<algorithm>
#include<cmath>
#include<string>
#include<iomanip>
#include<numeric>
#include<queue>
#include<deque>
#include<stack>
#include<set>
#include<map>
#include<random>
#include<bitset>
#include<cassert>
#include<complex>
#include<fstream>
#include<cstdlib>
#include<functional>
#include<array>
using namespace std;
typedef long long ll;
const int mod=998244353;
int main(){
	int h,w;
	string s[3000];
	cin>>h>>w;
	for(int i=0;i<h;i++)
		cin>>s[i];
	string ans={s[0][0]};
	set<pair<int,int>>tmp={{0,0}};
	for(int i=0;i<h+w-2;i++){
		set<pair<int,int>>nxt;
		char c=-1;
		for(auto[x,y]:tmp){
			if(x!=h-1){
				if(c==-1||c>s[x+1][y]){
					c=s[x+1][y];
					nxt.clear();
				}
				if(c==s[x+1][y])
					nxt.insert({x+1,y});
			}
			if(y!=w-1){
				if(c==-1||c>s[x][y+1]){
					c=s[x][y+1];
					nxt.clear();
				}
				if(c==s[x][y+1])
					nxt.insert({x,y+1});
			}
		}
		ans+=c;
		tmp.swap(nxt);
	}
	cout<<ans<<endl;
}
0