Submission #91833

# Submission time Handle Problem Language Result Execution time Memory
91833 2018-12-30T09:47:05 Z emil_physmath Chessboard (IZhO18_chessboard) C++14
70 / 100
1754 ms 2652 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("%lld%lld%lld%lld", 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:59: warning: format '%lld' expects argument of type 'long long int*', but argument 2 has type 'int*' [-Wformat=]
   scanf("%lld%lld%lld%lld", mini+i, minj+i, maxi+i, maxj+i);
                             ~~~~~~                        ^
chessboard.cpp:16:59: warning: format '%lld' expects argument of type 'long long int*', but argument 3 has type 'int*' [-Wformat=]
chessboard.cpp:16:59: warning: format '%lld' expects argument of type 'long long int*', but argument 4 has type 'int*' [-Wformat=]
chessboard.cpp:16:59: warning: format '%lld' expects argument of type 'long long int*', but argument 5 has type 'int*' [-Wformat=]
chessboard.cpp:16: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 252 KB Output is correct
4 Correct 1 ms 256 KB Output is correct
5 Correct 1 ms 256 KB Output is correct
6 Correct 1 ms 256 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 33 ms 1784 KB Output is correct
2 Correct 10 ms 888 KB Output is correct
3 Correct 22 ms 1528 KB Output is correct
4 Correct 23 ms 1744 KB Output is correct
5 Correct 29 ms 1784 KB Output is correct
6 Correct 20 ms 1528 KB Output is correct
7 Correct 5 ms 632 KB Output is correct
8 Correct 19 ms 1528 KB Output is correct
9 Correct 47 ms 2424 KB Output is correct
10 Correct 27 ms 1784 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 3 ms 256 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 380 KB Output is correct
8 Correct 2 ms 376 KB Output is correct
9 Correct 2 ms 376 KB Output is correct
10 Correct 1 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 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 376 KB Output is correct
2 Correct 3 ms 256 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 380 KB Output is correct
8 Correct 2 ms 376 KB Output is correct
9 Correct 2 ms 376 KB Output is correct
10 Correct 1 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 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 21 ms 1144 KB Output is correct
17 Correct 38 ms 2296 KB Output is correct
18 Correct 73 ms 2576 KB Output is correct
19 Correct 353 ms 2372 KB Output is correct
20 Correct 382 ms 2652 KB Output is correct
21 Correct 37 ms 2268 KB Output is correct
22 Correct 3 ms 376 KB Output is correct
23 Correct 53 ms 1660 KB Output is correct
24 Correct 66 ms 2280 KB Output is correct
25 Correct 12 ms 632 KB Output is correct
26 Correct 41 ms 1784 KB Output is correct
27 Correct 68 ms 2052 KB Output is correct
28 Correct 69 ms 2424 KB Output is correct
29 Correct 16 ms 1400 KB Output is correct
30 Correct 4 ms 376 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 33 ms 1784 KB Output is correct
2 Correct 10 ms 888 KB Output is correct
3 Correct 22 ms 1528 KB Output is correct
4 Correct 23 ms 1744 KB Output is correct
5 Correct 29 ms 1784 KB Output is correct
6 Correct 20 ms 1528 KB Output is correct
7 Correct 5 ms 632 KB Output is correct
8 Correct 19 ms 1528 KB Output is correct
9 Correct 47 ms 2424 KB Output is correct
10 Correct 27 ms 1784 KB Output is correct
11 Correct 2 ms 376 KB Output is correct
12 Correct 3 ms 256 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 380 KB Output is correct
18 Correct 2 ms 376 KB Output is correct
19 Correct 2 ms 376 KB Output is correct
20 Correct 1 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 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 21 ms 1144 KB Output is correct
27 Correct 38 ms 2296 KB Output is correct
28 Correct 73 ms 2576 KB Output is correct
29 Correct 353 ms 2372 KB Output is correct
30 Correct 382 ms 2652 KB Output is correct
31 Correct 37 ms 2268 KB Output is correct
32 Correct 3 ms 376 KB Output is correct
33 Correct 53 ms 1660 KB Output is correct
34 Correct 66 ms 2280 KB Output is correct
35 Correct 12 ms 632 KB Output is correct
36 Correct 41 ms 1784 KB Output is correct
37 Correct 68 ms 2052 KB Output is correct
38 Correct 69 ms 2424 KB Output is correct
39 Correct 16 ms 1400 KB Output is correct
40 Correct 4 ms 376 KB Output is correct
41 Correct 427 ms 2396 KB Output is correct
42 Correct 74 ms 2424 KB Output is correct
43 Correct 161 ms 2300 KB Output is correct
44 Correct 74 ms 2512 KB Output is correct
45 Correct 53 ms 2552 KB Output is correct
46 Correct 321 ms 2524 KB Output is correct
47 Correct 46 ms 2300 KB Output is correct
48 Correct 118 ms 2388 KB Output is correct
49 Correct 67 ms 2296 KB Output is correct
50 Correct 1576 ms 2424 KB Output is correct
51 Correct 1678 ms 2424 KB Output is correct
52 Correct 1563 ms 2424 KB Output is correct
53 Correct 1675 ms 2532 KB Output is correct
54 Correct 1551 ms 2424 KB Output is correct
55 Correct 1750 ms 2556 KB Output is correct
56 Correct 1495 ms 2424 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 252 KB Output is correct
4 Correct 1 ms 256 KB Output is correct
5 Correct 1 ms 256 KB Output is correct
6 Correct 1 ms 256 KB Output is correct
7 Correct 2 ms 256 KB Output is correct
8 Correct 2 ms 256 KB Output is correct
9 Correct 33 ms 1784 KB Output is correct
10 Correct 10 ms 888 KB Output is correct
11 Correct 22 ms 1528 KB Output is correct
12 Correct 23 ms 1744 KB Output is correct
13 Correct 29 ms 1784 KB Output is correct
14 Correct 20 ms 1528 KB Output is correct
15 Correct 5 ms 632 KB Output is correct
16 Correct 19 ms 1528 KB Output is correct
17 Correct 47 ms 2424 KB Output is correct
18 Correct 27 ms 1784 KB Output is correct
19 Correct 2 ms 376 KB Output is correct
20 Correct 3 ms 256 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 380 KB Output is correct
26 Correct 2 ms 376 KB Output is correct
27 Correct 2 ms 376 KB Output is correct
28 Correct 1 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 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 21 ms 1144 KB Output is correct
35 Correct 38 ms 2296 KB Output is correct
36 Correct 73 ms 2576 KB Output is correct
37 Correct 353 ms 2372 KB Output is correct
38 Correct 382 ms 2652 KB Output is correct
39 Correct 37 ms 2268 KB Output is correct
40 Correct 3 ms 376 KB Output is correct
41 Correct 53 ms 1660 KB Output is correct
42 Correct 66 ms 2280 KB Output is correct
43 Correct 12 ms 632 KB Output is correct
44 Correct 41 ms 1784 KB Output is correct
45 Correct 68 ms 2052 KB Output is correct
46 Correct 69 ms 2424 KB Output is correct
47 Correct 16 ms 1400 KB Output is correct
48 Correct 4 ms 376 KB Output is correct
49 Correct 427 ms 2396 KB Output is correct
50 Correct 74 ms 2424 KB Output is correct
51 Correct 161 ms 2300 KB Output is correct
52 Correct 74 ms 2512 KB Output is correct
53 Correct 53 ms 2552 KB Output is correct
54 Correct 321 ms 2524 KB Output is correct
55 Correct 46 ms 2300 KB Output is correct
56 Correct 118 ms 2388 KB Output is correct
57 Correct 67 ms 2296 KB Output is correct
58 Correct 1576 ms 2424 KB Output is correct
59 Correct 1678 ms 2424 KB Output is correct
60 Correct 1563 ms 2424 KB Output is correct
61 Correct 1675 ms 2532 KB Output is correct
62 Correct 1551 ms 2424 KB Output is correct
63 Correct 1750 ms 2556 KB Output is correct
64 Correct 1495 ms 2424 KB Output is correct
65 Correct 2 ms 376 KB Output is correct
66 Correct 2 ms 256 KB Output is correct
67 Correct 1636 ms 2448 KB Output is correct
68 Correct 1622 ms 2448 KB Output is correct
69 Correct 1421 ms 2168 KB Output is correct
70 Correct 1561 ms 2396 KB Output is correct
71 Correct 1562 ms 2376 KB Output is correct
72 Correct 1499 ms 2340 KB Output is correct
73 Correct 1490 ms 2320 KB Output is correct
74 Correct 1618 ms 2552 KB Output is correct
75 Correct 1525 ms 2012 KB Output is correct
76 Correct 1636 ms 2040 KB Output is correct
77 Correct 239 ms 2072 KB Output is correct
78 Correct 75 ms 2040 KB Output is correct
79 Correct 158 ms 1820 KB Output is correct
80 Correct 163 ms 1880 KB Output is correct
81 Correct 151 ms 1768 KB Output is correct
82 Correct 160 ms 1976 KB Output is correct
83 Correct 94 ms 1784 KB Output is correct
84 Correct 952 ms 2000 KB Output is correct
85 Correct 1754 ms 2140 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 -