結果

問題 No.1668 Grayscale
ユーザー 沙耶花沙耶花
提出日時 2021-09-03 22:36:07
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 753 ms / 4,000 ms
コード長 922 bytes
コンパイル時間 4,302 ms
コンパイル使用メモリ 262,784 KB
実行使用メモリ 65,832 KB
最終ジャッジ日時 2023-08-21 23:27:41
合計ジャッジ時間 7,672 ms
ジャッジサーバーID
(参考情報)
judge14 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 1 ms
4,380 KB
testcase_03 AC 1 ms
4,380 KB
testcase_04 AC 2 ms
4,380 KB
testcase_05 AC 1 ms
4,380 KB
testcase_06 AC 280 ms
65,764 KB
testcase_07 AC 282 ms
65,832 KB
testcase_08 AC 84 ms
7,420 KB
testcase_09 AC 753 ms
64,496 KB
testcase_10 AC 205 ms
30,032 KB
testcase_11 AC 2 ms
4,380 KB
testcase_12 AC 2 ms
4,380 KB
testcase_13 AC 22 ms
6,852 KB
testcase_14 AC 77 ms
14,240 KB
testcase_15 AC 44 ms
9,088 KB
testcase_16 AC 29 ms
7,120 KB
testcase_17 AC 16 ms
5,532 KB
testcase_18 AC 1 ms
4,380 KB
testcase_19 AC 2 ms
4,380 KB
testcase_20 AC 2 ms
4,380 KB
testcase_21 AC 2 ms
4,376 KB
testcase_22 AC 2 ms
4,380 KB
testcase_23 AC 2 ms
4,380 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