結果

問題 No.2064 Smallest Sequence on Grid
ユーザー kotatsugame
提出日時 2022-09-02 23:31:53
言語 C++14
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 935 ms / 3,000 ms
コード長 780 bytes
コンパイル時間 953 ms
コンパイル使用メモリ 84,896 KB
実行使用メモリ 15,104 KB
最終ジャッジ日時 2024-11-16 06:33:35
合計ジャッジ時間 10,339 ms
ジャッジサーバーID
(参考情報)
judge5 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2
other AC * 29
権限があれば一括ダウンロードができます

ソースコード

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