Submission #57567212


Source Code Expand

// LUOGU_RID: 176232591
#include<bits/stdc++.h>
using namespace std;
const int N=5e6+10;
int mx[4]={1,-1,0,0},my[4]={0,0,1,-1};
int h,w,q,ans;
pair<int,int>fa[5][N];
inline int calc(int x,int y)
{
	return x*(w+2)+y;
}
inline pair<int,int> find(int p,int x,int y)
{
	if(fa[p][calc(x,y)]==make_pair(x,y))
		return {x,y};
	return fa[p][calc(x,y)]=find(p,fa[p][calc(x,y)].first,fa[p][calc(x,y)].second);
}
inline void ch(int x,int y)
{
	if(x<=0||x>h||y<=0||y>w)
		return ;
	ans--;
	for(int i=0;i<4;i++)
		fa[i][calc(x,y)]={x+mx[i],y+my[i]};
	return ;
}
int main()
{
	ios::sync_with_stdio(0);
	cin.tie(0); cout.tie(0);
	cin>>h>>w>>q;
	ans=h*w;
	for(int i=0;i<=h+1;i++)
		for(int j=0;j<=w+1;j++)
			for(int k=0;k<4;k++)
				fa[k][calc(i,j)]={i,j};
	for(int i=1,r,c;i<=q;i++)
	{
		cin>>r>>c;
		if(fa[1][calc(r,c)]==make_pair(r,c))
			ch(r,c);
		else
			for(int j=0;j<4;j++)
			{
				pair<int,int>g=find(j,r,c);
				ch(g.first,g.second);
			}
	}
	cout<<ans<<"\n";
	return 0;
}

Submission Info

Submission Time
Task D - Cross Explosion
User lxyt_415x
Language C++ 17 (gcc 12.2)
Score 400
Code Size 1017 Byte
Status AC
Exec Time 81 ms
Memory 40912 KiB

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 400 / 400
Status
AC × 3
AC × 26
Set Name Test Cases
Sample 00_sample_00.txt, 00_sample_01.txt, 00_sample_02.txt
All 00_sample_00.txt, 00_sample_01.txt, 00_sample_02.txt, 01_random_00.txt, 01_random_01.txt, 01_random_02.txt, 01_random_03.txt, 01_random_04.txt, 01_random_05.txt, 01_random_06.txt, 01_random_07.txt, 01_random_08.txt, 01_random_09.txt, 01_random_10.txt, 01_random_11.txt, 01_random_12.txt, 01_random_13.txt, 01_random_14.txt, 01_random_15.txt, 01_random_16.txt, 01_random_17.txt, 01_random_18.txt, 01_random_19.txt, 02_all_break_00.txt, 03_hack_00.txt, 03_hack_01.txt
Case Name Status Exec Time Memory
00_sample_00.txt AC 1 ms 3420 KiB
00_sample_01.txt AC 1 ms 3616 KiB
00_sample_02.txt AC 1 ms 3408 KiB
01_random_00.txt AC 62 ms 18592 KiB
01_random_01.txt AC 42 ms 18244 KiB
01_random_02.txt AC 46 ms 18252 KiB
01_random_03.txt AC 58 ms 18528 KiB
01_random_04.txt AC 66 ms 16752 KiB
01_random_05.txt AC 67 ms 18152 KiB
01_random_06.txt AC 74 ms 17944 KiB
01_random_07.txt AC 41 ms 18120 KiB
01_random_08.txt AC 45 ms 30960 KiB
01_random_09.txt AC 73 ms 16088 KiB
01_random_10.txt AC 40 ms 18696 KiB
01_random_11.txt AC 42 ms 16620 KiB
01_random_12.txt AC 55 ms 20200 KiB
01_random_13.txt AC 70 ms 16404 KiB
01_random_14.txt AC 48 ms 16056 KiB
01_random_15.txt AC 73 ms 16380 KiB
01_random_16.txt AC 48 ms 16256 KiB
01_random_17.txt AC 59 ms 20148 KiB
01_random_18.txt AC 81 ms 16060 KiB
01_random_19.txt AC 43 ms 16060 KiB
02_all_break_00.txt AC 30 ms 16044 KiB
03_hack_00.txt AC 34 ms 40904 KiB
03_hack_01.txt AC 33 ms 40912 KiB