Submission #91835

# Submission time Handle Problem Language Result Execution time Memory
91835 2018-12-30T09:50:29 Z emil_physmath Chessboard (IZhO18_chessboard) C++17
70 / 100
1736 ms 1992 KB
#include <iostream>
#include <stdio.h>
using namespace std;
const int MAXK=100005;

int 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, int k, int cellLen);
int main()
{
	long long n;
	int k;
	cin>>n>>k;
	for (int i=0; i<k; i++)
		scanf("%d%d%d%d", mini+i, minj+i, maxi+i, maxj+i);
	long long  ans=n*n;
	for (int cellLen=1; 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, int k, int cellLen)
{
	if (cellLen>=n) return n*n;
	long long shouldWhite=0, shouldBlack=0, isBlack=0;
	for (int i=0; i<k; i++)
	{
		shouldWhite+=NumWhite(mini[i], minj[i], maxi[i], maxj[i], cellLen);
		isBlack+=(maxi[i]-mini[i]+1)*(maxj[i]-minj[i]+1);
	}
	shouldBlack=(n*n-NumWhite(1, 1, 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=1;
	if (!minj) minj=1;
	if (mini==1 && minj==1)
	{
		long long  ans=0, i=maxi, j=maxj;
		ans+=len*len*(((i/len)*(j/len)+1)/2);
		if ((i/len)%2)
			ans+=(i%len)*((j/len)/2)*len;
		else
			ans+=(i%len)*((j/len+1)/2)*len;
		if ((j/len)%2)
			ans+=(j%len)*((i/len)/2)*len;
		else
			ans+=(j%len)*((i/len+1)/2)*len;
		if ((i/len)%2==(j/len)%2)
			ans+=(i%len)*(j%len);
		return ans;
	}
	return NumWhite(1, 1, maxi, maxj, len)-
		NumWhite(1, 1, maxi, minj-1, len)-NumWhite(1, 1, mini-1, maxj, len)+
		NumWhite(1, 1, mini-1, minj-1, len);
}

Compilation message

chessboard.cpp: In function 'int main()':
chessboard.cpp:16:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%d%d%d%d", 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 256 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 1272 KB Output is correct
2 Correct 11 ms 632 KB Output is correct
3 Correct 23 ms 1016 KB Output is correct
4 Correct 24 ms 1020 KB Output is correct
5 Correct 31 ms 1272 KB Output is correct
6 Correct 20 ms 888 KB Output is correct
7 Correct 6 ms 508 KB Output is correct
8 Correct 20 ms 888 KB Output is correct
9 Correct 48 ms 1656 KB Output is correct
10 Correct 28 ms 1272 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 3 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 3 ms 376 KB Output is correct
8 Correct 3 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 3 ms 376 KB Output is correct
12 Correct 2 ms 376 KB Output is correct
13 Correct 3 ms 376 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 3 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 3 ms 376 KB Output is correct
8 Correct 3 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 3 ms 376 KB Output is correct
12 Correct 2 ms 376 KB Output is correct
13 Correct 3 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 22 ms 760 KB Output is correct
17 Correct 40 ms 1656 KB Output is correct
18 Correct 73 ms 1912 KB Output is correct
19 Correct 349 ms 1784 KB Output is correct
20 Correct 457 ms 1912 KB Output is correct
21 Correct 38 ms 1656 KB Output is correct
22 Correct 3 ms 380 KB Output is correct
23 Correct 55 ms 1016 KB Output is correct
24 Correct 66 ms 1784 KB Output is correct
25 Correct 12 ms 504 KB Output is correct
26 Correct 42 ms 1272 KB Output is correct
27 Correct 68 ms 1400 KB Output is correct
28 Correct 70 ms 1868 KB Output is correct
29 Correct 17 ms 888 KB Output is correct
30 Correct 3 ms 376 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 34 ms 1272 KB Output is correct
2 Correct 11 ms 632 KB Output is correct
3 Correct 23 ms 1016 KB Output is correct
4 Correct 24 ms 1020 KB Output is correct
5 Correct 31 ms 1272 KB Output is correct
6 Correct 20 ms 888 KB Output is correct
7 Correct 6 ms 508 KB Output is correct
8 Correct 20 ms 888 KB Output is correct
9 Correct 48 ms 1656 KB Output is correct
10 Correct 28 ms 1272 KB Output is correct
11 Correct 2 ms 380 KB Output is correct
12 Correct 2 ms 376 KB Output is correct
13 Correct 3 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 3 ms 376 KB Output is correct
18 Correct 3 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 3 ms 376 KB Output is correct
22 Correct 2 ms 376 KB Output is correct
23 Correct 3 ms 376 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 760 KB Output is correct
27 Correct 40 ms 1656 KB Output is correct
28 Correct 73 ms 1912 KB Output is correct
29 Correct 349 ms 1784 KB Output is correct
30 Correct 457 ms 1912 KB Output is correct
31 Correct 38 ms 1656 KB Output is correct
32 Correct 3 ms 380 KB Output is correct
33 Correct 55 ms 1016 KB Output is correct
34 Correct 66 ms 1784 KB Output is correct
35 Correct 12 ms 504 KB Output is correct
36 Correct 42 ms 1272 KB Output is correct
37 Correct 68 ms 1400 KB Output is correct
38 Correct 70 ms 1868 KB Output is correct
39 Correct 17 ms 888 KB Output is correct
40 Correct 3 ms 376 KB Output is correct
41 Correct 289 ms 1784 KB Output is correct
42 Correct 74 ms 1880 KB Output is correct
43 Correct 153 ms 1676 KB Output is correct
44 Correct 75 ms 1788 KB Output is correct
45 Correct 54 ms 1784 KB Output is correct
46 Correct 323 ms 1824 KB Output is correct
47 Correct 47 ms 1656 KB Output is correct
48 Correct 118 ms 1820 KB Output is correct
49 Correct 70 ms 1656 KB Output is correct
50 Correct 1565 ms 1876 KB Output is correct
51 Correct 1646 ms 1912 KB Output is correct
52 Correct 1569 ms 1784 KB Output is correct
53 Correct 1679 ms 1904 KB Output is correct
54 Correct 1557 ms 1796 KB Output is correct
55 Correct 1736 ms 1956 KB Output is correct
56 Correct 1501 ms 1712 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 256 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 1272 KB Output is correct
10 Correct 11 ms 632 KB Output is correct
11 Correct 23 ms 1016 KB Output is correct
12 Correct 24 ms 1020 KB Output is correct
13 Correct 31 ms 1272 KB Output is correct
14 Correct 20 ms 888 KB Output is correct
15 Correct 6 ms 508 KB Output is correct
16 Correct 20 ms 888 KB Output is correct
17 Correct 48 ms 1656 KB Output is correct
18 Correct 28 ms 1272 KB Output is correct
19 Correct 2 ms 380 KB Output is correct
20 Correct 2 ms 376 KB Output is correct
21 Correct 3 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 3 ms 376 KB Output is correct
26 Correct 3 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 3 ms 376 KB Output is correct
30 Correct 2 ms 376 KB Output is correct
31 Correct 3 ms 376 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 760 KB Output is correct
35 Correct 40 ms 1656 KB Output is correct
36 Correct 73 ms 1912 KB Output is correct
37 Correct 349 ms 1784 KB Output is correct
38 Correct 457 ms 1912 KB Output is correct
39 Correct 38 ms 1656 KB Output is correct
40 Correct 3 ms 380 KB Output is correct
41 Correct 55 ms 1016 KB Output is correct
42 Correct 66 ms 1784 KB Output is correct
43 Correct 12 ms 504 KB Output is correct
44 Correct 42 ms 1272 KB Output is correct
45 Correct 68 ms 1400 KB Output is correct
46 Correct 70 ms 1868 KB Output is correct
47 Correct 17 ms 888 KB Output is correct
48 Correct 3 ms 376 KB Output is correct
49 Correct 289 ms 1784 KB Output is correct
50 Correct 74 ms 1880 KB Output is correct
51 Correct 153 ms 1676 KB Output is correct
52 Correct 75 ms 1788 KB Output is correct
53 Correct 54 ms 1784 KB Output is correct
54 Correct 323 ms 1824 KB Output is correct
55 Correct 47 ms 1656 KB Output is correct
56 Correct 118 ms 1820 KB Output is correct
57 Correct 70 ms 1656 KB Output is correct
58 Correct 1565 ms 1876 KB Output is correct
59 Correct 1646 ms 1912 KB Output is correct
60 Correct 1569 ms 1784 KB Output is correct
61 Correct 1679 ms 1904 KB Output is correct
62 Correct 1557 ms 1796 KB Output is correct
63 Correct 1736 ms 1956 KB Output is correct
64 Correct 1501 ms 1712 KB Output is correct
65 Correct 2 ms 376 KB Output is correct
66 Correct 2 ms 376 KB Output is correct
67 Correct 1640 ms 1832 KB Output is correct
68 Correct 1623 ms 1912 KB Output is correct
69 Correct 1412 ms 1660 KB Output is correct
70 Correct 1680 ms 1784 KB Output is correct
71 Correct 1514 ms 1784 KB Output is correct
72 Correct 1463 ms 1784 KB Output is correct
73 Correct 1462 ms 1756 KB Output is correct
74 Correct 1592 ms 1784 KB Output is correct
75 Correct 1497 ms 1784 KB Output is correct
76 Correct 1620 ms 1784 KB Output is correct
77 Correct 235 ms 1912 KB Output is correct
78 Correct 73 ms 1912 KB Output is correct
79 Correct 160 ms 1660 KB Output is correct
80 Correct 166 ms 1784 KB Output is correct
81 Correct 151 ms 1528 KB Output is correct
82 Correct 125 ms 1892 KB Output is correct
83 Correct 93 ms 1652 KB Output is correct
84 Correct 957 ms 1784 KB Output is correct
85 Correct 1720 ms 1992 KB Output is correct
86 Correct 3 ms 376 KB Output is correct
87 Incorrect 2 ms 376 KB Output isn't correct
88 Halted 0 ms 0 KB -