Submission #91831

# Submission time Handle Problem Language Result Execution time Memory
91831 2018-12-30T09:42:27 Z emil_physmath Chessboard (IZhO18_chessboard) C++14
100 / 100
1747 ms 5880 KB
#include <iostream>
#include <stdio.h>
using namespace std;
const long long MAXK=100005;
 
long long mini[MAXK], maxi[MAXK], minj[MAXK], maxj[MAXK];
 
long long NumWhite(long long, long long, long long, long long, long long cellLen);
long long FindAns(long long n, long long k, long long cellLen);
int main()
{
	long long n, k;
	cin>>n>>k;
	for (long long i=0; i<k; i++)
		scanf("%lld%lld%lld%lld", mini+i, minj+i, maxi+i, maxj+i);
	long long ans=n*n;
	for (long long cellLen=1LL; cellLen*cellLen<=n; cellLen++)
		if (n%cellLen==0)
		{
			ans=min(ans, FindAns(n, k, cellLen));
			ans=min(ans, FindAns(n, k, n/cellLen));
		}
	cout<<ans<<'\n';
 
	char I;
	cin >> I;
	return 0;
}
 
long long FindAns(long long n, long long k, long long cellLen)
{
	if (cellLen>=n) return n*n;
	long long shouldWhite=0, shouldBlack=0, isBlack=0;
	for (long long i=0; i<k; i++)
	{
		shouldWhite+=NumWhite(mini[i], minj[i], maxi[i], maxj[i], cellLen);
		isBlack+=(maxi[i]-mini[i]+1LL)*(maxj[i]-minj[i]+1LL);
	}
	shouldBlack=(n*n-NumWhite(1LL, 1LL, n, n, cellLen))-(isBlack-shouldWhite);
	return min(shouldWhite+shouldBlack, n*n-(shouldWhite+shouldBlack));
}
long long NumWhite(long long mini, long long minj, long long maxi, long long maxj, long long len)
{
	if (!mini) mini=1LL;
	if (!minj) minj=1LL;
	if (mini==1LL && minj==1LL)
	{
		long long ans=0, i=maxi, j=maxj;
		ans+=len*len*(((i/len)*(j/len)+1LL)/2LL);
		if ((i/len)%2LL)
			ans+=(i%len)*((j/len)/2LL)*len;
		else
			ans+=(i%len)*((j/len+1LL)/2LL)*len;
		if ((j/len)%2LL)
			ans+=(j%len)*((i/len)/2LL)*len;
		else
			ans+=(j%len)*((i/len+1LL)/2LL)*len;
		if ((i/len)%2LL==(j/len)%2LL)
			ans+=(i%len)*(j%len);
		return ans;
	}
	return NumWhite(1LL, 1LL, maxi, maxj, len)-
		NumWhite(1LL, 1LL, maxi, minj-1LL, len)-NumWhite(1LL, 1LL, mini-1LL, maxj, len)+
		NumWhite(1LL, 1LL, mini-1LL, minj-1LL, len);
}
//#include <iostream>
//#include <stdio.h>
//#include <set>
//using namespace std;
//const long long MAXK=1LL00005;
//
//long long mini[MAXK], maxi[MAXK], minj[MAXK], maxj[MAXK];
//
//bool IsWhite(long long, long long);
//long long FindAns(long long n, long long k);
//int main()
//{
//	long long n, k;
//	cin>>n>>k;
//	for (long long i=0; i<k; i++)
//		scanf("%lld%lld%lld%lld", mini+i, minj+i, maxi+i, maxj+i);
//	cout<<FindAns(n, k)<<'\n';
//
//	char I;
//	cin >> I;
//	return 0;
//}
//
//long long FindAns(long long n, long long k)
//{
//	long long shouldWhite=0, shouldBlack=(n*n)/2LL;
//	for (long long i=0; i<k; i++)
//    {
//		if (IsWhite(maxi[i], maxj[i]))
//			shouldWhite++;
//      	else
//          	shouldBlack--;
//	}
//	return min(1LLLL+shouldWhite+shouldBlack, n*n-(shouldWhite+shouldBlack));
//}
//
//bool IsWhite(long long i, long long j)
//{
//	return ((i+j)%2LL==0);
//}

Compilation message

chessboard.cpp: In function 'int main()':
chessboard.cpp:15:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%lld%lld%lld%lld", mini+i, minj+i, maxi+i, maxj+i);
   ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 376 KB Output is correct
4 Correct 2 ms 376 KB Output is correct
5 Correct 2 ms 376 KB Output is correct
6 Correct 2 ms 376 KB Output is correct
7 Correct 2 ms 256 KB Output is correct
8 Correct 2 ms 256 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 34 ms 2296 KB Output is correct
2 Correct 10 ms 888 KB Output is correct
3 Correct 23 ms 2424 KB Output is correct
4 Correct 24 ms 2552 KB Output is correct
5 Correct 30 ms 3320 KB Output is correct
6 Correct 20 ms 2216 KB Output is correct
7 Correct 6 ms 764 KB Output is correct
8 Correct 21 ms 2296 KB Output is correct
9 Correct 49 ms 5240 KB Output is correct
10 Correct 28 ms 3064 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 380 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 376 KB Output is correct
4 Correct 3 ms 376 KB Output is correct
5 Correct 2 ms 376 KB Output is correct
6 Correct 2 ms 376 KB Output is correct
7 Correct 2 ms 376 KB Output is correct
8 Correct 2 ms 376 KB Output is correct
9 Correct 2 ms 376 KB Output is correct
10 Correct 2 ms 376 KB Output is correct
11 Correct 2 ms 376 KB Output is correct
12 Correct 2 ms 376 KB Output is correct
13 Correct 3 ms 380 KB Output is correct
14 Correct 3 ms 376 KB Output is correct
15 Correct 2 ms 376 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 380 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 376 KB Output is correct
4 Correct 3 ms 376 KB Output is correct
5 Correct 2 ms 376 KB Output is correct
6 Correct 2 ms 376 KB Output is correct
7 Correct 2 ms 376 KB Output is correct
8 Correct 2 ms 376 KB Output is correct
9 Correct 2 ms 376 KB Output is correct
10 Correct 2 ms 376 KB Output is correct
11 Correct 2 ms 376 KB Output is correct
12 Correct 2 ms 376 KB Output is correct
13 Correct 3 ms 380 KB Output is correct
14 Correct 3 ms 376 KB Output is correct
15 Correct 2 ms 376 KB Output is correct
16 Correct 22 ms 1656 KB Output is correct
17 Correct 41 ms 4372 KB Output is correct
18 Correct 76 ms 5052 KB Output is correct
19 Correct 351 ms 4476 KB Output is correct
20 Correct 392 ms 5160 KB Output is correct
21 Correct 39 ms 4088 KB Output is correct
22 Correct 3 ms 380 KB Output is correct
23 Correct 55 ms 2300 KB Output is correct
24 Correct 68 ms 4728 KB Output is correct
25 Correct 12 ms 760 KB Output is correct
26 Correct 43 ms 3064 KB Output is correct
27 Correct 70 ms 3576 KB Output is correct
28 Correct 73 ms 4860 KB Output is correct
29 Correct 17 ms 1912 KB Output is correct
30 Correct 4 ms 376 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 34 ms 2296 KB Output is correct
2 Correct 10 ms 888 KB Output is correct
3 Correct 23 ms 2424 KB Output is correct
4 Correct 24 ms 2552 KB Output is correct
5 Correct 30 ms 3320 KB Output is correct
6 Correct 20 ms 2216 KB Output is correct
7 Correct 6 ms 764 KB Output is correct
8 Correct 21 ms 2296 KB Output is correct
9 Correct 49 ms 5240 KB Output is correct
10 Correct 28 ms 3064 KB Output is correct
11 Correct 2 ms 380 KB Output is correct
12 Correct 2 ms 376 KB Output is correct
13 Correct 2 ms 376 KB Output is correct
14 Correct 3 ms 376 KB Output is correct
15 Correct 2 ms 376 KB Output is correct
16 Correct 2 ms 376 KB Output is correct
17 Correct 2 ms 376 KB Output is correct
18 Correct 2 ms 376 KB Output is correct
19 Correct 2 ms 376 KB Output is correct
20 Correct 2 ms 376 KB Output is correct
21 Correct 2 ms 376 KB Output is correct
22 Correct 2 ms 376 KB Output is correct
23 Correct 3 ms 380 KB Output is correct
24 Correct 3 ms 376 KB Output is correct
25 Correct 2 ms 376 KB Output is correct
26 Correct 22 ms 1656 KB Output is correct
27 Correct 41 ms 4372 KB Output is correct
28 Correct 76 ms 5052 KB Output is correct
29 Correct 351 ms 4476 KB Output is correct
30 Correct 392 ms 5160 KB Output is correct
31 Correct 39 ms 4088 KB Output is correct
32 Correct 3 ms 380 KB Output is correct
33 Correct 55 ms 2300 KB Output is correct
34 Correct 68 ms 4728 KB Output is correct
35 Correct 12 ms 760 KB Output is correct
36 Correct 43 ms 3064 KB Output is correct
37 Correct 70 ms 3576 KB Output is correct
38 Correct 73 ms 4860 KB Output is correct
39 Correct 17 ms 1912 KB Output is correct
40 Correct 4 ms 376 KB Output is correct
41 Correct 284 ms 4956 KB Output is correct
42 Correct 78 ms 5624 KB Output is correct
43 Correct 163 ms 4984 KB Output is correct
44 Correct 75 ms 5496 KB Output is correct
45 Correct 55 ms 5880 KB Output is correct
46 Correct 331 ms 5368 KB Output is correct
47 Correct 46 ms 5024 KB Output is correct
48 Correct 117 ms 5164 KB Output is correct
49 Correct 68 ms 4984 KB Output is correct
50 Correct 1569 ms 5468 KB Output is correct
51 Correct 1671 ms 5752 KB Output is correct
52 Correct 1591 ms 5368 KB Output is correct
53 Correct 1700 ms 5752 KB Output is correct
54 Correct 1548 ms 5260 KB Output is correct
55 Correct 1747 ms 5880 KB Output is correct
56 Correct 1497 ms 5112 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 376 KB Output is correct
4 Correct 2 ms 376 KB Output is correct
5 Correct 2 ms 376 KB Output is correct
6 Correct 2 ms 376 KB Output is correct
7 Correct 2 ms 256 KB Output is correct
8 Correct 2 ms 256 KB Output is correct
9 Correct 34 ms 2296 KB Output is correct
10 Correct 10 ms 888 KB Output is correct
11 Correct 23 ms 2424 KB Output is correct
12 Correct 24 ms 2552 KB Output is correct
13 Correct 30 ms 3320 KB Output is correct
14 Correct 20 ms 2216 KB Output is correct
15 Correct 6 ms 764 KB Output is correct
16 Correct 21 ms 2296 KB Output is correct
17 Correct 49 ms 5240 KB Output is correct
18 Correct 28 ms 3064 KB Output is correct
19 Correct 2 ms 380 KB Output is correct
20 Correct 2 ms 376 KB Output is correct
21 Correct 2 ms 376 KB Output is correct
22 Correct 3 ms 376 KB Output is correct
23 Correct 2 ms 376 KB Output is correct
24 Correct 2 ms 376 KB Output is correct
25 Correct 2 ms 376 KB Output is correct
26 Correct 2 ms 376 KB Output is correct
27 Correct 2 ms 376 KB Output is correct
28 Correct 2 ms 376 KB Output is correct
29 Correct 2 ms 376 KB Output is correct
30 Correct 2 ms 376 KB Output is correct
31 Correct 3 ms 380 KB Output is correct
32 Correct 3 ms 376 KB Output is correct
33 Correct 2 ms 376 KB Output is correct
34 Correct 22 ms 1656 KB Output is correct
35 Correct 41 ms 4372 KB Output is correct
36 Correct 76 ms 5052 KB Output is correct
37 Correct 351 ms 4476 KB Output is correct
38 Correct 392 ms 5160 KB Output is correct
39 Correct 39 ms 4088 KB Output is correct
40 Correct 3 ms 380 KB Output is correct
41 Correct 55 ms 2300 KB Output is correct
42 Correct 68 ms 4728 KB Output is correct
43 Correct 12 ms 760 KB Output is correct
44 Correct 43 ms 3064 KB Output is correct
45 Correct 70 ms 3576 KB Output is correct
46 Correct 73 ms 4860 KB Output is correct
47 Correct 17 ms 1912 KB Output is correct
48 Correct 4 ms 376 KB Output is correct
49 Correct 284 ms 4956 KB Output is correct
50 Correct 78 ms 5624 KB Output is correct
51 Correct 163 ms 4984 KB Output is correct
52 Correct 75 ms 5496 KB Output is correct
53 Correct 55 ms 5880 KB Output is correct
54 Correct 331 ms 5368 KB Output is correct
55 Correct 46 ms 5024 KB Output is correct
56 Correct 117 ms 5164 KB Output is correct
57 Correct 68 ms 4984 KB Output is correct
58 Correct 1569 ms 5468 KB Output is correct
59 Correct 1671 ms 5752 KB Output is correct
60 Correct 1591 ms 5368 KB Output is correct
61 Correct 1700 ms 5752 KB Output is correct
62 Correct 1548 ms 5260 KB Output is correct
63 Correct 1747 ms 5880 KB Output is correct
64 Correct 1497 ms 5112 KB Output is correct
65 Correct 2 ms 376 KB Output is correct
66 Correct 1 ms 376 KB Output is correct
67 Correct 1629 ms 5500 KB Output is correct
68 Correct 1673 ms 5496 KB Output is correct
69 Correct 1408 ms 4724 KB Output is correct
70 Correct 1589 ms 5336 KB Output is correct
71 Correct 1551 ms 5240 KB Output is correct
72 Correct 1502 ms 5240 KB Output is correct
73 Correct 1486 ms 4984 KB Output is correct
74 Correct 1640 ms 5496 KB Output is correct
75 Correct 1510 ms 5216 KB Output is correct
76 Correct 1650 ms 5548 KB Output is correct
77 Correct 248 ms 5812 KB Output is correct
78 Correct 75 ms 5288 KB Output is correct
79 Correct 161 ms 5040 KB Output is correct
80 Correct 165 ms 5248 KB Output is correct
81 Correct 159 ms 4884 KB Output is correct
82 Correct 128 ms 5540 KB Output is correct
83 Correct 94 ms 5140 KB Output is correct
84 Correct 942 ms 5688 KB Output is correct
85 Correct 1735 ms 5780 KB Output is correct
86 Correct 3 ms 376 KB Output is correct
87 Correct 2 ms 376 KB Output is correct
88 Correct 1741 ms 5876 KB Output is correct
89 Correct 320 ms 1400 KB Output is correct
90 Correct 2 ms 376 KB Output is correct