結果

問題 No.2696 Sign Creation
ユーザー 沙耶花沙耶花
提出日時 2024-03-22 21:46:26
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 86 ms / 2,500 ms
コード長 1,358 bytes
コンパイル時間 4,584 ms
コンパイル使用メモリ 269,368 KB
実行使用メモリ 6,676 KB
最終ジャッジ日時 2024-03-27 17:57:46
合計ジャッジ時間 6,535 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
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 2 ms
6,676 KB
testcase_05 AC 2 ms
6,676 KB
testcase_06 AC 2 ms
6,676 KB
testcase_07 AC 2 ms
6,676 KB
testcase_08 AC 3 ms
6,676 KB
testcase_09 AC 2 ms
6,676 KB
testcase_10 AC 3 ms
6,676 KB
testcase_11 AC 3 ms
6,676 KB
testcase_12 AC 3 ms
6,676 KB
testcase_13 AC 86 ms
6,676 KB
testcase_14 AC 36 ms
6,676 KB
testcase_15 AC 31 ms
6,676 KB
testcase_16 AC 73 ms
6,676 KB
testcase_17 AC 29 ms
6,676 KB
testcase_18 AC 24 ms
6,676 KB
testcase_19 AC 41 ms
6,676 KB
testcase_20 AC 5 ms
6,676 KB
testcase_21 AC 28 ms
6,676 KB
testcase_22 AC 38 ms
6,676 KB
testcase_23 AC 34 ms
6,676 KB
testcase_24 AC 33 ms
6,676 KB
testcase_25 AC 49 ms
6,676 KB
testcase_26 AC 32 ms
6,676 KB
testcase_27 AC 38 ms
6,676 KB
testcase_28 AC 34 ms
6,676 KB
testcase_29 AC 32 ms
6,676 KB
testcase_30 AC 33 ms
6,676 KB
testcase_31 AC 79 ms
6,676 KB
testcase_32 AC 2 ms
6,676 KB
testcase_33 AC 2 ms
6,676 KB
testcase_34 AC 2 ms
6,676 KB
testcase_35 AC 2 ms
6,676 KB
testcase_36 AC 2 ms
6,676 KB
testcase_37 AC 2 ms
6,676 KB
testcase_38 AC 2 ms
6,676 KB
testcase_39 AC 2 ms
6,676 KB
testcase_40 AC 3 ms
6,676 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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

int main(){
	
	ios::sync_with_stdio(false);
	std::cin.tie(nullptr);
	
	int H,W,N,D;
	cin>>H>>W>>N>>D;
	
	vector p(H,vector<int>(W,-1));
	rep(i,N){
		int a,b;
		cin>>a>>b;
		a--,b--;
		p[a][b] = i;
	}
	dsu d(N);
	rep(i,H){
		rep(j,W){
			if(p[i][j]==-1)continue;
			for(int dx=-5;dx<=5;dx++){
				for(int dy=-5;dy<=5;dy++){
					if(abs(dx)+abs(dy)>D)continue;
					int x = i+dx,y = j+dy;
					if(x<0||x>=H||y<0||y>=W)continue;
					if(p[x][y]!=-1)d.merge(p[i][j],p[x][y]);
				}
			}
			
		}
	}
	
	int cur = 0;
	rep(i,N){
		if(d.leader(i)==i && d.size(i)>=2)cur++;
	}

	int m = Inf32,M = -Inf32;
	rep(i,H){
		rep(j,W){
			if(p[i][j]!=-1)continue;
			set<int> cnt;
			for(int dx=-5;dx<=5;dx++){
				for(int dy=-5;dy<=5;dy++){
					if(abs(dx)+abs(dy)>D)continue;
					int x = i+dx,y = j+dy;
					if(x<0||x>=H||y<0||y>=W)continue;
					if(p[x][y]!=-1)cnt.insert(d.leader(p[x][y]));//d.merge(p[i][j],p[x][y]);
				}
			}
			
			int x = cur;
			if(cnt.size()!=0){
				x ++;
				for(auto aa:cnt){
					if(d.size(aa)!=1)x--;
				}
			}
			m = min(m,x);
			M = max(M,x);
		}
	}
	
	cout<<m<<' '<<M<<endl;
	return 0;
}
0