답안 #93194

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
93194 2019-01-07T06:16:55 Z antimirage Chessboard (IZhO18_chessboard) C++14
100 / 100
911 ms 3156 KB
#include <bits/stdc++.h>
 
#define fr first
#define sc second
#define mk make_pair
#define pb emplace_back
#define all(s) s.begin(), s.end()
 
using namespace std;

const int N = 1e5 + 5;

int m, x1[N], yy1[N], x2[N], y2[N];

long long n, ans = 1e18;

long long compute (int j1, int j2, long long bl)
{
	if (j1 / bl == j2 / bl)
	{
		if (j1 / bl & 1)
			return (j2 - j1 + 1);
		
		return 0ll;
	}
	long long res = 0;
	
	if (j1 / bl & 1)
		res += (j1 / bl * bl + bl - j1);
	
	j1 = j1 / bl * bl + bl;
	
	if (j2 / bl & 1)
		res += (j2 % bl + 1);
		
	j2 = j2 / bl * bl - 1;
	
	long long cn = (j2 / bl - j1 / bl + 1) / 2;
	
	if ( ((j2 / bl - j1 / bl + 1) & 1) && (j2 / bl & 1) )
		cn++;
	
	res += cn * bl;
	return res;
}

long long get (int i1, int j1, int i2, int j2, long long bl)
{
	long long res = 0, cn1 = compute( j1, j2, bl ), cn2 = (j2 - j1 + 1) - cn1;
	
	if (i1 / bl == i2 / bl)
	{
		if (i1 / bl & 1)
			res += cn1 * (i2 - i1 + 1);
		else
			res += cn2 * (i2 - i1 + 1);
	}
	else
	{
		if (i1 / bl & 1)
			res += cn1 * (i1 / bl * bl + bl - i1);
		else
			res += cn2 * (i1 / bl * bl + bl - i1);
			
		i1 = i1 / bl * bl + bl;
		
		if (i2 / bl & 1)
			res += cn1 * (i2 % bl + 1);
		else
			res += cn2 * (i2 % bl + 1);
			
		i2 = i2 / bl * bl - 1;
		
		long long cn = (i2 / bl - i1 / bl + 1) / 2;
		
		if ( (i2 / bl - i1 / bl + 1) & 1 )
		{
			if ( i1 / bl % 2 == 0 )
			{
				res += (cn + 1) * cn2 * bl;
				res += cn * cn1 * bl;
			}
			else
			{
				res += (cn + 1) * cn1 * bl;
				res += cn * cn2 * bl;
			}
		}
		else
		{
			res += cn * cn1 * bl;
			res += cn * cn2 * bl;
		}
	}
	return res;
}

void calc (long long x)
{
	long long res = get(0, 0, n - 1, n - 1, x) ;
	
	for (int i = 1; i <= m; i++)
	{
		long long sup = get( x1[i], yy1[i], x2[i], y2[i], x);
		res -= sup;
		res += ( (x2[i] - x1[i] + 1) * 1ll * (y2[i] - yy1[i] + 1) - sup);
	}
	ans = min(ans, res);
	ans = min(ans, n * n - res);
}

main() 
{
	cin >> n >> m;
	for (int i = 1; i <= m; i++)
	{
		scanf("%d %d %d %d", &x1[i], &yy1[i], &x2[i], &y2[i]);
		x1[i]--;
		yy1[i]--;
		x2[i]--;
		y2[i]--;
	}
	for (long long i = 1; i * i <= n; i++)
	{
		if ( n % i != 0 ) continue;
		calc(i);
		if (n / i != n)
			calc(n / i);
	}
	cout << ans << endl;
}
/**
6 8
3 3 3 3
1 2 1 2
3 4 3 4
5 5 5 5
4 3 4 3
4 4 4 4
2 1 2 1
3 6 3 6
**/

Compilation message

chessboard.cpp:112:6: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
 main() 
      ^
chessboard.cpp: In function 'int main()':
chessboard.cpp:117:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%d %d %d %d", &x1[i], &yy1[i], &x2[i], &y2[i]);
   ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 256 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 256 KB Output is correct
6 Correct 2 ms 256 KB Output is correct
7 Correct 2 ms 256 KB Output is correct
8 Correct 2 ms 380 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 31 ms 2552 KB Output is correct
2 Correct 10 ms 760 KB Output is correct
3 Correct 21 ms 1748 KB Output is correct
4 Correct 22 ms 1832 KB Output is correct
5 Correct 27 ms 2396 KB Output is correct
6 Correct 18 ms 1656 KB Output is correct
7 Correct 5 ms 504 KB Output is correct
8 Correct 18 ms 1528 KB Output is correct
9 Correct 44 ms 2936 KB Output is correct
10 Correct 26 ms 2108 KB Output is correct
# 결과 실행 시간 메모리 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 3 ms 380 KB Output is correct
5 Correct 3 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 380 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 2 ms 376 KB Output is correct
15 Correct 2 ms 376 KB Output is correct
# 결과 실행 시간 메모리 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 3 ms 380 KB Output is correct
5 Correct 3 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 380 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 2 ms 376 KB Output is correct
15 Correct 2 ms 376 KB Output is correct
16 Correct 17 ms 1016 KB Output is correct
17 Correct 35 ms 2808 KB Output is correct
18 Correct 52 ms 3064 KB Output is correct
19 Correct 175 ms 2808 KB Output is correct
20 Correct 195 ms 3064 KB Output is correct
21 Correct 34 ms 2936 KB Output is correct
22 Correct 14 ms 376 KB Output is correct
23 Correct 34 ms 1656 KB Output is correct
24 Correct 48 ms 2808 KB Output is correct
25 Correct 8 ms 504 KB Output is correct
26 Correct 32 ms 1964 KB Output is correct
27 Correct 47 ms 2424 KB Output is correct
28 Correct 50 ms 2976 KB Output is correct
29 Correct 15 ms 1272 KB Output is correct
30 Correct 3 ms 380 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 31 ms 2552 KB Output is correct
2 Correct 10 ms 760 KB Output is correct
3 Correct 21 ms 1748 KB Output is correct
4 Correct 22 ms 1832 KB Output is correct
5 Correct 27 ms 2396 KB Output is correct
6 Correct 18 ms 1656 KB Output is correct
7 Correct 5 ms 504 KB Output is correct
8 Correct 18 ms 1528 KB Output is correct
9 Correct 44 ms 2936 KB Output is correct
10 Correct 26 ms 2108 KB Output is correct
11 Correct 2 ms 376 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 380 KB Output is correct
15 Correct 3 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 380 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 2 ms 376 KB Output is correct
25 Correct 2 ms 376 KB Output is correct
26 Correct 17 ms 1016 KB Output is correct
27 Correct 35 ms 2808 KB Output is correct
28 Correct 52 ms 3064 KB Output is correct
29 Correct 175 ms 2808 KB Output is correct
30 Correct 195 ms 3064 KB Output is correct
31 Correct 34 ms 2936 KB Output is correct
32 Correct 14 ms 376 KB Output is correct
33 Correct 34 ms 1656 KB Output is correct
34 Correct 48 ms 2808 KB Output is correct
35 Correct 8 ms 504 KB Output is correct
36 Correct 32 ms 1964 KB Output is correct
37 Correct 47 ms 2424 KB Output is correct
38 Correct 50 ms 2976 KB Output is correct
39 Correct 15 ms 1272 KB Output is correct
40 Correct 3 ms 380 KB Output is correct
41 Correct 149 ms 2808 KB Output is correct
42 Correct 56 ms 2892 KB Output is correct
43 Correct 90 ms 2808 KB Output is correct
44 Correct 54 ms 2936 KB Output is correct
45 Correct 47 ms 2936 KB Output is correct
46 Correct 167 ms 2936 KB Output is correct
47 Correct 42 ms 2776 KB Output is correct
48 Correct 76 ms 2808 KB Output is correct
49 Correct 53 ms 2808 KB Output is correct
50 Correct 775 ms 2936 KB Output is correct
51 Correct 793 ms 2936 KB Output is correct
52 Correct 730 ms 2824 KB Output is correct
53 Correct 789 ms 2908 KB Output is correct
54 Correct 715 ms 2808 KB Output is correct
55 Correct 814 ms 3064 KB Output is correct
56 Correct 707 ms 2748 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 256 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 256 KB Output is correct
6 Correct 2 ms 256 KB Output is correct
7 Correct 2 ms 256 KB Output is correct
8 Correct 2 ms 380 KB Output is correct
9 Correct 31 ms 2552 KB Output is correct
10 Correct 10 ms 760 KB Output is correct
11 Correct 21 ms 1748 KB Output is correct
12 Correct 22 ms 1832 KB Output is correct
13 Correct 27 ms 2396 KB Output is correct
14 Correct 18 ms 1656 KB Output is correct
15 Correct 5 ms 504 KB Output is correct
16 Correct 18 ms 1528 KB Output is correct
17 Correct 44 ms 2936 KB Output is correct
18 Correct 26 ms 2108 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 3 ms 380 KB Output is correct
23 Correct 3 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 380 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 2 ms 376 KB Output is correct
33 Correct 2 ms 376 KB Output is correct
34 Correct 17 ms 1016 KB Output is correct
35 Correct 35 ms 2808 KB Output is correct
36 Correct 52 ms 3064 KB Output is correct
37 Correct 175 ms 2808 KB Output is correct
38 Correct 195 ms 3064 KB Output is correct
39 Correct 34 ms 2936 KB Output is correct
40 Correct 14 ms 376 KB Output is correct
41 Correct 34 ms 1656 KB Output is correct
42 Correct 48 ms 2808 KB Output is correct
43 Correct 8 ms 504 KB Output is correct
44 Correct 32 ms 1964 KB Output is correct
45 Correct 47 ms 2424 KB Output is correct
46 Correct 50 ms 2976 KB Output is correct
47 Correct 15 ms 1272 KB Output is correct
48 Correct 3 ms 380 KB Output is correct
49 Correct 149 ms 2808 KB Output is correct
50 Correct 56 ms 2892 KB Output is correct
51 Correct 90 ms 2808 KB Output is correct
52 Correct 54 ms 2936 KB Output is correct
53 Correct 47 ms 2936 KB Output is correct
54 Correct 167 ms 2936 KB Output is correct
55 Correct 42 ms 2776 KB Output is correct
56 Correct 76 ms 2808 KB Output is correct
57 Correct 53 ms 2808 KB Output is correct
58 Correct 775 ms 2936 KB Output is correct
59 Correct 793 ms 2936 KB Output is correct
60 Correct 730 ms 2824 KB Output is correct
61 Correct 789 ms 2908 KB Output is correct
62 Correct 715 ms 2808 KB Output is correct
63 Correct 814 ms 3064 KB Output is correct
64 Correct 707 ms 2748 KB Output is correct
65 Correct 2 ms 376 KB Output is correct
66 Correct 2 ms 376 KB Output is correct
67 Correct 851 ms 2936 KB Output is correct
68 Correct 854 ms 2936 KB Output is correct
69 Correct 723 ms 2780 KB Output is correct
70 Correct 784 ms 2808 KB Output is correct
71 Correct 807 ms 2824 KB Output is correct
72 Correct 771 ms 2680 KB Output is correct
73 Correct 798 ms 2680 KB Output is correct
74 Correct 860 ms 2844 KB Output is correct
75 Correct 799 ms 2808 KB Output is correct
76 Correct 869 ms 2936 KB Output is correct
77 Correct 144 ms 2936 KB Output is correct
78 Correct 59 ms 2808 KB Output is correct
79 Correct 107 ms 2680 KB Output is correct
80 Correct 109 ms 2680 KB Output is correct
81 Correct 103 ms 2684 KB Output is correct
82 Correct 89 ms 2880 KB Output is correct
83 Correct 71 ms 2740 KB Output is correct
84 Correct 513 ms 2904 KB Output is correct
85 Correct 906 ms 3064 KB Output is correct
86 Correct 3 ms 376 KB Output is correct
87 Correct 2 ms 256 KB Output is correct
88 Correct 911 ms 3156 KB Output is correct
89 Correct 180 ms 1104 KB Output is correct
90 Correct 2 ms 376 KB Output is correct