UOJ Logo

NOI.AC

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#205937#388. K皇后hujunyi66100121ms1568kbC++1.1kb2024-07-20 18:01:432024-07-20 20:04:03

answer

#include <iostream>
#include <cstdio>
#include <fstream>
#include <algorithm>
#include <cstring>
using namespace std;
typedef pair<int, int> PII;
const int N = 2e4 + 10, M = 510;
PII q[M];
int row[N], col[N], dg[N * 10], udg[N * 10];
int n, m, k;
int res;
int flag[N];
int main()
{
	cin>>n>>m>>k;
	
	for (int i=0;i<k;i++)
	{
		int x,y;
		cin>>x>>y;
		q[i].first=x,q[i].second=y;
		row[x]=col[y]=dg[x+y]=udg[y-x+n+m]=1;
	}
	for(int i=1;i<=n;i++)
	{
		if (row[i]) continue;
		
		int sum=m;
		
		for (int j=0;j<k;j++)
		{
			int a=q[j].first,b=q[j].second;
			
			if (flag[b]!= i) sum--;
			flag[b]=i;
			 
			if (a<i)
			{
				if (b-(i-a)>=1)
				{
					if (flag[b-(i-a)]!=i) sum--;
					flag[b-(i-a)]=i;
				}
				if (b+(i-a)<=m)
				{
					if (flag[b+(i-a)]!=i) sum--;
					flag[b+(i-a)]=i;
				}
			}
			if (i<a)
			{
				if (b+(a-i)<=m)
				{
					if (flag[b+(a-i)]!=i) sum--;
					flag[b+(a-i)]=i;
				}				
				if (b-(a-i)>=1)
				{
					if (flag[b-(a-i)]!=i) sum--;
					flag[b-(a-i)]=i;
				}
			}
		}
		
		res+=sum;
	}
	
	cout<<res<<endl;

	return 0;
}

详细

小提示:点击横条可展开更详细的信息

Test #1:

score: 10
Accepted
time: 23ms
memory: 1372kb

input:

12223 262 465
6044 59
2598 41
4885 107
2304 230
3563 75
8303 203
10824 100
5271 135
5912 169
6078 20...

output:

763937

result:

ok single line: '763937'

Test #2:

score: 10
Accepted
time: 34ms
memory: 1552kb

input:

14377 10341 362
10522 8568
11540 3334
13812 6760
10374 142
13647 3894
12498 5277
13142 9769
4132 101...

output:

134821283

result:

ok single line: '134821283'

Test #3:

score: 10
Accepted
time: 0ms
memory: 1400kb

input:

11851 4797 33
1922 1878
5819 4285
10749 292
1229 3148
3035 4377
2899 289
11500 519
11113 154
3657 65...

output:

56044703

result:

ok single line: '56044703'

Test #4:

score: 10
Accepted
time: 17ms
memory: 1568kb

input:

5429 18349 363
3988 337
4442 5193
4335 18170
3034 4232
4297 5608
3693 7426
4878 9843
2478 14537
2615...

output:

88190696

result:

ok single line: '88190696'

Test #5:

score: 10
Accepted
time: 4ms
memory: 1308kb

input:

3339 2956 156
805 2722
480 495
120 1429
1916 845
2692 2049
339 1602
2206 2513
7 1229
803 802
127 151...

output:

8372891

result:

ok single line: '8372891'

Test #6:

score: 10
Accepted
time: 4ms
memory: 1372kb

input:

4305 6551 231
4198 3012
3541 5350
2326 543
1057 1466
2502 1193
1807 4671
661 403
1669 1125
1780 3341...

output:

24429251

result:

ok single line: '24429251'

Test #7:

score: 10
Accepted
time: 11ms
memory: 1316kb

input:

4578 2845 403
674 129
2747 1788
4257 1097
2907 461
61 865
496 1056
841 2240
157 1134
4199 2015
2151 ...

output:

9077099

result:

ok single line: '9077099'

Test #8:

score: 10
Accepted
time: 0ms
memory: 1256kb

input:

705 1825 399
304 1406
400 360
607 1376
331 1503
269 1151
60 1031
476 825
46 1377
471 204
346 880
306...

output:

444849

result:

ok single line: '444849'

Test #9:

score: 10
Accepted
time: 9ms
memory: 1420kb

input:

3805 10401 301
2841 9099
676 6384
1171 6133
3215 5616
2911 988
3385 5083
3697 7828
1927 8980
3773 65...

output:

33774910

result:

ok single line: '33774910'

Test #10:

score: 10
Accepted
time: 19ms
memory: 1452kb

input:

19684 393 241
4857 166
11733 226
6757 188
3487 272
5615 326
16787 130
2405 76
12747 235
4945 141
133...

output:

4137138

result:

ok single line: '4137138'