結果

問題 No.2064 Smallest Sequence on Grid
ユーザー kotatsugamekotatsugame
提出日時 2022-09-02 23:31:53
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 905 ms / 3,000 ms
コード長 780 bytes
コンパイル時間 898 ms
コンパイル使用メモリ 83,640 KB
実行使用メモリ 15,104 KB
最終ジャッジ日時 2024-04-27 23:11:22
合計ジャッジ時間 9,754 ms
ジャッジサーバーID
(参考情報)
judge5 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,812 KB
testcase_01 AC 1 ms
6,940 KB
testcase_02 AC 1 ms
6,940 KB
testcase_03 AC 2 ms
6,944 KB
testcase_04 AC 1 ms
6,944 KB
testcase_05 AC 1 ms
6,944 KB
testcase_06 AC 2 ms
6,944 KB
testcase_07 AC 2 ms
6,944 KB
testcase_08 AC 2 ms
6,944 KB
testcase_09 AC 2 ms
6,944 KB
testcase_10 AC 2 ms
6,944 KB
testcase_11 AC 2 ms
6,944 KB
testcase_12 AC 2 ms
6,940 KB
testcase_13 AC 2 ms
6,944 KB
testcase_14 AC 2 ms
6,940 KB
testcase_15 AC 1 ms
6,944 KB
testcase_16 AC 2 ms
6,944 KB
testcase_17 AC 164 ms
14,848 KB
testcase_18 AC 166 ms
14,848 KB
testcase_19 AC 165 ms
14,848 KB
testcase_20 AC 700 ms
15,104 KB
testcase_21 AC 735 ms
15,104 KB
testcase_22 AC 533 ms
14,976 KB
testcase_23 AC 536 ms
15,104 KB
testcase_24 AC 535 ms
15,104 KB
testcase_25 AC 538 ms
15,104 KB
testcase_26 AC 905 ms
15,104 KB
testcase_27 AC 891 ms
14,976 KB
testcase_28 AC 169 ms
14,848 KB
testcase_29 AC 766 ms
14,976 KB
testcase_30 AC 153 ms
14,208 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
int H,W;
string S[3000];
int main()
{
	cin>>H>>W;
	for(int i=0;i<H;i++)cin>>S[i];
	string ans="";
	vector<pair<int,int> >xy;
	xy.push_back(make_pair(0,0));
	for(int t=0;t<H+W-1;t++)
	{
		ans+=S[xy[0].first][xy[0].second];
		if(t==H+W-2)break;
		vector<pair<char,pair<int,int> > >nxt;
		for(pair<int,int>p:xy)
		{
			int x=p.first,y=p.second;
			if(x+1<H)nxt.push_back(make_pair(S[x+1][y],make_pair(x+1,y)));
			if(y+1<W)nxt.push_back(make_pair(S[x][y+1],make_pair(x,y+1)));
		}
		sort(nxt.begin(),nxt.end());
		xy.clear();
		for(pair<char,pair<int,int> >p:nxt)
		{
			if(p.first>nxt[0].first)break;
			xy.push_back(p.second);
		}
		xy.erase(unique(xy.begin(),xy.end()),xy.end());
	}
	cout<<ans<<endl;
}
0