結果

問題 No.2731 Two Colors
ユーザー 沙耶花沙耶花
提出日時 2024-04-19 21:42:20
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 2,229 ms / 3,000 ms
コード長 1,231 bytes
コンパイル時間 4,674 ms
コンパイル使用メモリ 263,772 KB
実行使用メモリ 73,984 KB
最終ジャッジ日時 2024-04-19 21:42:49
合計ジャッジ時間 24,390 ms
ジャッジサーバーID
(参考情報)
judge5 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2,219 ms
73,984 KB
testcase_01 AC 2,229 ms
73,856 KB
testcase_02 AC 2,193 ms
73,984 KB
testcase_03 AC 7 ms
5,376 KB
testcase_04 AC 47 ms
6,912 KB
testcase_05 AC 32 ms
5,376 KB
testcase_06 AC 150 ms
12,032 KB
testcase_07 AC 176 ms
14,976 KB
testcase_08 AC 20 ms
5,376 KB
testcase_09 AC 667 ms
47,360 KB
testcase_10 AC 9 ms
5,376 KB
testcase_11 AC 688 ms
36,924 KB
testcase_12 AC 676 ms
47,232 KB
testcase_13 AC 560 ms
31,360 KB
testcase_14 AC 297 ms
21,760 KB
testcase_15 AC 19 ms
5,376 KB
testcase_16 AC 289 ms
16,980 KB
testcase_17 AC 397 ms
25,560 KB
testcase_18 AC 58 ms
7,040 KB
testcase_19 AC 271 ms
17,408 KB
testcase_20 AC 439 ms
33,024 KB
testcase_21 AC 63 ms
7,168 KB
testcase_22 AC 754 ms
44,800 KB
testcase_23 AC 160 ms
12,864 KB
testcase_24 AC 74 ms
8,064 KB
testcase_25 AC 5 ms
5,376 KB
testcase_26 AC 567 ms
38,144 KB
testcase_27 AC 702 ms
46,404 KB
testcase_28 AC 454 ms
27,412 KB
testcase_29 AC 161 ms
10,752 KB
testcase_30 AC 249 ms
18,048 KB
testcase_31 AC 151 ms
11,264 KB
testcase_32 AC 901 ms
51,168 KB
testcase_33 AC 2 ms
5,376 KB
testcase_34 AC 2 ms
5,376 KB
testcase_35 AC 2 ms
5,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <stdio.h>
#include <bits/stdc++.h>
#include <atcoder/all>
using namespace atcoder;
using mint = modint998244353;
using namespace std;
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define Inf32 1000000001
#define Inf64 1000000000000000001

int main(){
	
	int h,w;
	cin>>h>>w;
	vector<vector<int>> a(h,vector<int>(w));
	rep(i,h){
		rep(j,w)cin>>a[i][j];
	}
	map<int,pair<int,int>> mp;
	rep(i,h){
		rep(j,w)mp[a[i][j]] = make_pair(i,j);
	}
	vector ans(h,vector<int>(w,-1));
	
	vector<int> dx = {1,-1,0,0},dy = {0,0,1,-1};
	vector<priority_queue<int,vector<int>,greater<int>>> Q(2);
	rep(i,2){
		int x = 0,y = 0;
		if(i)x = h-1,y = w-1;
		ans[x][y] = i;
		rep(j,4){
			int xx = x+dx[j],yy = y+dy[j];
			//cout<<xx<<' '<<yy<<endl;
			if(xx<0||yy<0||xx>=h||yy>=w)continue;
			Q[i].push(a[xx][yy]);
		}
	}
	rep(_,10000000){
		int i = _%2;
		while(true){
			int u = Q[i].top();
			Q[i].pop();
			int x  =mp[u].first,y = mp[u].second;
			if(ans[x][y]!=-1)continue;
			
			ans[x][y] = i;
			rep(j,4){
				int xx = x+dx[j],yy = y+dy[j];
				if(xx<0||xx>=h||yy<0||yy>=w)continue;
				if(ans[xx][yy]!=-1 && ans[xx][yy]!=i){
					cout<<_+1<<endl;
					return 0;
				}
				Q[i].push(a[xx][yy]);
			}
			break;
		}
		
	}
	
	return 0;
}
0