結果

問題 No.1668 Grayscale
ユーザー 沙耶花沙耶花
提出日時 2021-09-03 22:36:07
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 747 ms / 4,000 ms
コード長 922 bytes
コンパイル時間 4,567 ms
コンパイル使用メモリ 265,024 KB
実行使用メモリ 66,028 KB
最終ジャッジ日時 2024-05-09 05:27:26
合計ジャッジ時間 7,254 ms
ジャッジサーバーID
(参考情報)
judge1 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,248 KB
testcase_01 AC 2 ms
5,376 KB
testcase_02 AC 2 ms
5,376 KB
testcase_03 AC 2 ms
5,376 KB
testcase_04 AC 2 ms
5,376 KB
testcase_05 AC 2 ms
5,376 KB
testcase_06 AC 287 ms
66,008 KB
testcase_07 AC 283 ms
66,028 KB
testcase_08 AC 97 ms
7,552 KB
testcase_09 AC 747 ms
64,640 KB
testcase_10 AC 218 ms
30,464 KB
testcase_11 AC 2 ms
5,376 KB
testcase_12 AC 3 ms
5,376 KB
testcase_13 AC 25 ms
7,040 KB
testcase_14 AC 88 ms
14,464 KB
testcase_15 AC 49 ms
9,216 KB
testcase_16 AC 32 ms
7,424 KB
testcase_17 AC 17 ms
5,888 KB
testcase_18 AC 2 ms
5,376 KB
testcase_19 AC 2 ms
5,376 KB
testcase_20 AC 2 ms
5,376 KB
testcase_21 AC 3 ms
5,376 KB
testcase_22 AC 2 ms
5,376 KB
testcase_23 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 Inf 1000000001

int main(){
	
	int H,W,N;
	cin>>H>>W>>N;
	
	vector A(H,vector<int>(W));
	rep(i,H){
		rep(j,W){
			scanf("%d",&A[i][j]);
			A[i][j]--;
		}
	}
	vector<vector<int>> E(N);
	vector dx = {0,0,1,-1},dy = {1,-1,0,0};
	
	vector<bool> ok(N-1,true);
	
	rep(i,H){
		rep(j,W){
			rep(k,4){
				int ii = i+dx[k],jj = j+dy[k];
				if(ii<0||ii>=H||jj<0||jj>=W)continue;
				
				if(A[i][j] != A[ii][jj]){
					E[A[i][j]].push_back(A[ii][jj]);
				}
			}
		}
	}
	
	dsu D(N);
	rep(i,N){
		if(i==0)continue;
		bool f = true;
		rep(j,E[i].size()){
			if(D.same(E[i][j],i-1)){
				f = false;
				break;
			}
		}
		if(f)D.merge(i,i-1);
	}
	
	int ans = 0;
	rep(i,N){
		if(D.leader(i)==i)ans++;
	}
	
	cout<<ans<<endl;
	
	return 0;
}
0