結果

問題 No.2639 Longest Increasing Walk
ユーザー daiotadaiota
提出日時 2024-02-20 10:45:31
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 465 ms / 2,000 ms
コード長 1,083 bytes
コンパイル時間 2,101 ms
コンパイル使用メモリ 185,052 KB
実行使用メモリ 23,924 KB
最終ジャッジ日時 2024-02-20 10:45:39
合計ジャッジ時間 8,111 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,676 KB
testcase_01 AC 2 ms
6,676 KB
testcase_02 AC 2 ms
6,676 KB
testcase_03 AC 2 ms
6,676 KB
testcase_04 AC 286 ms
23,924 KB
testcase_05 AC 178 ms
23,924 KB
testcase_06 AC 185 ms
23,548 KB
testcase_07 AC 216 ms
23,548 KB
testcase_08 AC 188 ms
23,668 KB
testcase_09 AC 230 ms
23,796 KB
testcase_10 AC 431 ms
16,088 KB
testcase_11 AC 375 ms
13,824 KB
testcase_12 AC 30 ms
6,676 KB
testcase_13 AC 465 ms
16,744 KB
testcase_14 AC 215 ms
10,920 KB
testcase_15 AC 2 ms
6,676 KB
testcase_16 AC 5 ms
6,676 KB
testcase_17 AC 137 ms
10,480 KB
testcase_18 AC 288 ms
12,252 KB
testcase_19 AC 47 ms
6,676 KB
testcase_20 AC 141 ms
8,728 KB
testcase_21 AC 375 ms
13,688 KB
testcase_22 AC 87 ms
7,408 KB
testcase_23 AC 2 ms
6,676 KB
testcase_24 AC 2 ms
6,676 KB
testcase_25 AC 3 ms
6,676 KB
testcase_26 AC 2 ms
6,676 KB
testcase_27 AC 4 ms
6,676 KB
testcase_28 AC 2 ms
6,676 KB
testcase_29 AC 2 ms
6,676 KB
testcase_30 AC 2 ms
6,676 KB
testcase_31 AC 2 ms
6,676 KB
testcase_32 AC 2 ms
6,676 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef pair<int,int> P;
typedef pair<int,P> Q;
#define REP(i,n) for(int i=0;i<int(n);i++)

int a[510][510];
int H,W;
bool inside(int i,int j){
	return (1<=i && i<=H && 1<=j && j<=W);
}


int main(){
	cin.tie(nullptr);  ios_base::sync_with_stdio(false);
	int i,j;


	cin >> H >> W;

	vector<Q> v;
	for(i=1;i<=H;i++) for(j=1;j<=W;j++){
		cin >> a[i][j];
		v.push_back(Q(a[i][j],P(i,j)));
	}

	sort(v.begin(),v.end());

	map<P,int> m;
	REP(i,H*W) m[P(v[i].second.first,v[i].second.second)]=i;

	vector<int> dp(H*W,1);
	REP(i,H*W){
		int x=v[i].second.first,y=v[i].second.second;

		int k=m[P(x+1,y)];
		if(inside(x+1,y) && a[x+1][y]>a[x][y]) dp[k]=max(dp[k],dp[i]+1);

		k=m[P(x,y+1)];
		if(inside(x,y+1) && a[x][y+1]>a[x][y]) dp[k]=max(dp[k],dp[i]+1);

		k=m[P(x-1,y)];
		if(inside(x-1,y) && a[x-1][y]>a[x][y]) dp[k]=max(dp[k],dp[i]+1);

		k=m[P(x,y-1)];
		if(inside(x,y-1) && a[x][y-1]>a[x][y]) dp[k]=max(dp[k],dp[i]+1);


	}


	int ans=1;
	REP(i,H*W) ans=max(ans,dp[i]);

	cout << ans << endl;


    return 0;
}
0