結果

問題 No.2696 Sign Creation
ユーザー kotatsugamekotatsugame
提出日時 2024-03-22 21:48:17
言語 C++23
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 80 ms / 2,500 ms
コード長 1,258 bytes
コンパイル時間 1,511 ms
コンパイル使用メモリ 111,144 KB
実行使用メモリ 10,036 KB
最終ジャッジ日時 2024-03-27 17:57:41
合計ジャッジ時間 3,051 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,548 KB
testcase_01 AC 2 ms
6,548 KB
testcase_02 AC 2 ms
6,548 KB
testcase_03 AC 2 ms
6,548 KB
testcase_04 AC 2 ms
6,548 KB
testcase_05 AC 2 ms
6,548 KB
testcase_06 AC 2 ms
6,548 KB
testcase_07 AC 2 ms
6,548 KB
testcase_08 AC 3 ms
6,548 KB
testcase_09 AC 2 ms
6,548 KB
testcase_10 AC 2 ms
6,548 KB
testcase_11 AC 4 ms
6,548 KB
testcase_12 AC 3 ms
6,548 KB
testcase_13 AC 80 ms
9,140 KB
testcase_14 AC 31 ms
9,140 KB
testcase_15 AC 28 ms
7,808 KB
testcase_16 AC 69 ms
7,552 KB
testcase_17 AC 26 ms
9,216 KB
testcase_18 AC 21 ms
8,832 KB
testcase_19 AC 37 ms
9,216 KB
testcase_20 AC 5 ms
6,548 KB
testcase_21 AC 23 ms
8,064 KB
testcase_22 AC 31 ms
9,728 KB
testcase_23 AC 30 ms
9,224 KB
testcase_24 AC 29 ms
9,172 KB
testcase_25 AC 44 ms
9,436 KB
testcase_26 AC 27 ms
9,472 KB
testcase_27 AC 29 ms
10,036 KB
testcase_28 AC 25 ms
10,036 KB
testcase_29 AC 28 ms
10,012 KB
testcase_30 AC 28 ms
9,992 KB
testcase_31 AC 69 ms
7,348 KB
testcase_32 AC 2 ms
6,548 KB
testcase_33 AC 2 ms
6,548 KB
testcase_34 AC 2 ms
6,548 KB
testcase_35 AC 2 ms
6,548 KB
testcase_36 AC 2 ms
6,548 KB
testcase_37 AC 2 ms
6,548 KB
testcase_38 AC 2 ms
6,548 KB
testcase_39 AC 2 ms
6,548 KB
testcase_40 AC 1 ms
6,548 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<iostream>
#include<vector>
#include<algorithm>
#include<cassert>
#include<atcoder/dsu>
using namespace std;
int H,W,N,D;
bool ex[1<<17];
void f(int x,int y,auto g)
{
	for(int dx=-D;dx<=D;dx++)
	{
		int nd=D-abs(dx);
		for(int dy=-nd;dy<=nd;dy++)if(dx!=0||dy!=0)
		{
			int tx=x+dx,ty=y+dy;
			if(tx<0||ty<0||tx>=H||ty>=W)continue;
			g(tx*W+ty);
		}
	}
}
bool in[1<<17];
int main()
{
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	cin>>H>>W>>N>>D;
	for(int i=0;i<N;i++)
	{
		int x,y;cin>>x>>y;x--,y--;
		ex[x*W+y]=true;
	}
	atcoder::dsu uf(H*W);
	for(int i=0;i<H*W;i++)if(ex[i])
	{
		int x=i/W,y=i%W;
		f(x,y,[&](int j){
			if(ex[j])
			{
				uf.merge(i,j);
			}
		});
	}
	int cnt=0;
	for(vector<int>g:uf.groups())if(g.size()>=2)
	{
		cnt++;
		for(int u:g)in[u]=true;
	}
	int ansmax=0,ansmin=1e9;
	vector<int>cur;
	for(int i=0;i<H*W;i++)if(!ex[i])
	{
		int x=i/W,y=i%W;
		cur.clear();
		f(x,y,[&](int j){
			if(ex[j])cur.push_back(uf.leader(j));
		});
		sort(cur.begin(),cur.end());
		cur.erase(unique(cur.begin(),cur.end()),cur.end());
		int now=cnt;
		if(cur.empty());
		else
		{
			now++;
			for(int u:cur)if(!in[u])now++;
			now-=(int)cur.size();
		}
		ansmax=max(ansmax,now);
		ansmin=min(ansmin,now);
	}
	cout<<ansmin<<" "<<ansmax<<endl;
}
0