結果

問題 No.2064 Smallest Sequence on Grid
ユーザー okkuukenkenokkuukenken
提出日時 2022-09-02 21:35:45
言語 C++23
(gcc 12.3.0 + boost 1.83.0)
結果
RE  
実行時間 -
コード長 993 bytes
コンパイル時間 1,874 ms
コンパイル使用メモリ 157,508 KB
実行使用メモリ 7,168 KB
最終ジャッジ日時 2024-04-27 21:03:08
合計ジャッジ時間 6,426 ms
ジャッジサーバーID
(参考情報)
judge2 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,812 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,940 KB
testcase_05 AC 1 ms
6,940 KB
testcase_06 AC 1 ms
6,940 KB
testcase_07 AC 2 ms
6,940 KB
testcase_08 AC 1 ms
6,944 KB
testcase_09 AC 2 ms
6,940 KB
testcase_10 AC 2 ms
6,944 KB
testcase_11 AC 1 ms
6,944 KB
testcase_12 AC 2 ms
6,940 KB
testcase_13 AC 1 ms
6,940 KB
testcase_14 AC 2 ms
6,944 KB
testcase_15 AC 1 ms
6,944 KB
testcase_16 AC 2 ms
6,940 KB
testcase_17 RE -
testcase_18 RE -
testcase_19 RE -
testcase_20 RE -
testcase_21 RE -
testcase_22 RE -
testcase_23 RE -
testcase_24 RE -
testcase_25 RE -
testcase_26 RE -
testcase_27 RE -
testcase_28 RE -
testcase_29 RE -
testcase_30 RE -
権限があれば一括ダウンロードができます

ソースコード

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[1000];
	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