답안 #241532

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
241532 2020-06-24T11:42:07 Z arnold518 Chessboard (IZhO18_chessboard) C++14
100 / 100
959 ms 2044 KB
#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

const int MAXN = 1e5;

struct Rect { int y1, x1, y2, x2; };
Rect A[MAXN+10];

int N, K;

ll f(int y, int x)
{
	if(y<0 || x<0) return 0;
	ll t=(ll)(y+1)*(x+1);
	return (t+1)/2;
}

ll g(int y, int x, int it)
{
	if(y<0 || x<0) return 0;
	int yy=(y+1)/it-1, xx=(x+1)/it-1;
	ll ret=0;
	ret+=f(yy, xx)*it*it;
	ret+=(ll)(x-(xx*it+it-1))*(f(yy, xx+1)-f(yy, xx))*it;
	ret+=(ll)(y-(yy*it+it-1))*(f(yy+1, xx)-f(yy, xx))*it;
	if((yy+xx)%2==0) ret+=(ll)(x-(xx*it+it-1))*(y-(yy*it+it-1));
	//printf("%d %d %d => %d %d %lld\n", y, x, it, yy, xx, ret);
	return ret;
}

int main()
{
	int i, j;

	scanf("%d%d", &N, &K);
	for(i=1; i<=K; i++) scanf("%d%d%d%d", &A[i].y1, &A[i].x1, &A[i].y2, &A[i].x2), A[i].y1--, A[i].x1--, A[i].y2--, A[i].x2--;

	vector<int> V;
	for(i=1; i<N; i++) if(N%i==0) V.push_back(i);

	ll ans=1e18;
	for(auto it : V)
	{
		ll a=0, b=0, c=0;
		for(i=1; i<=K; i++)
		{
			ll t=g(A[i].y2, A[i].x2, it)-g(A[i].y1-1, A[i].x2, it)-g(A[i].y2, A[i].x1-1, it)+g(A[i].y1-1, A[i].x1-1, it);
			a+=t;
			b+=(ll)(A[i].y2-A[i].y1+1)*(A[i].x2-A[i].x1+1);
		}
		c=((ll)(N/it)*(N/it)+1)/2*it*it-a;
		b=(ll)N*N-b;
		a+=b-c;
		//printf("%lld\n", a);
		ans=min(ans, min(a, (ll)N*N-a));
	}
	printf("%lld\n", ans);
}

Compilation message

chessboard.cpp: In function 'int main()':
chessboard.cpp:37:9: warning: unused variable 'j' [-Wunused-variable]
  int i, j;
         ^
chessboard.cpp:39:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d%d", &N, &K);
  ~~~~~^~~~~~~~~~~~~~~~
chessboard.cpp:40:112: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  for(i=1; i<=K; i++) scanf("%d%d%d%d", &A[i].y1, &A[i].x1, &A[i].y2, &A[i].x2), A[i].y1--, A[i].x1--, A[i].y2--, A[i].x2--;
                      ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 256 KB Output is correct
2 Correct 4 ms 256 KB Output is correct
3 Correct 5 ms 384 KB Output is correct
4 Correct 5 ms 256 KB Output is correct
5 Correct 5 ms 256 KB Output is correct
6 Correct 5 ms 256 KB Output is correct
7 Correct 4 ms 256 KB Output is correct
8 Correct 5 ms 384 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 36 ms 1272 KB Output is correct
2 Correct 13 ms 640 KB Output is correct
3 Correct 27 ms 896 KB Output is correct
4 Correct 26 ms 1024 KB Output is correct
5 Correct 32 ms 1272 KB Output is correct
6 Correct 23 ms 896 KB Output is correct
7 Correct 8 ms 384 KB Output is correct
8 Correct 23 ms 896 KB Output is correct
9 Correct 52 ms 1784 KB Output is correct
10 Correct 34 ms 1152 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 256 KB Output is correct
2 Correct 5 ms 384 KB Output is correct
3 Correct 6 ms 256 KB Output is correct
4 Correct 6 ms 384 KB Output is correct
5 Correct 5 ms 384 KB Output is correct
6 Correct 5 ms 384 KB Output is correct
7 Correct 5 ms 384 KB Output is correct
8 Correct 5 ms 384 KB Output is correct
9 Correct 5 ms 384 KB Output is correct
10 Correct 5 ms 384 KB Output is correct
11 Correct 5 ms 384 KB Output is correct
12 Correct 5 ms 384 KB Output is correct
13 Correct 5 ms 384 KB Output is correct
14 Correct 5 ms 384 KB Output is correct
15 Correct 5 ms 432 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 256 KB Output is correct
2 Correct 5 ms 384 KB Output is correct
3 Correct 6 ms 256 KB Output is correct
4 Correct 6 ms 384 KB Output is correct
5 Correct 5 ms 384 KB Output is correct
6 Correct 5 ms 384 KB Output is correct
7 Correct 5 ms 384 KB Output is correct
8 Correct 5 ms 384 KB Output is correct
9 Correct 5 ms 384 KB Output is correct
10 Correct 5 ms 384 KB Output is correct
11 Correct 5 ms 384 KB Output is correct
12 Correct 5 ms 384 KB Output is correct
13 Correct 5 ms 384 KB Output is correct
14 Correct 5 ms 384 KB Output is correct
15 Correct 5 ms 432 KB Output is correct
16 Correct 20 ms 768 KB Output is correct
17 Correct 40 ms 1656 KB Output is correct
18 Correct 61 ms 1912 KB Output is correct
19 Correct 203 ms 1664 KB Output is correct
20 Correct 221 ms 1912 KB Output is correct
21 Correct 40 ms 1532 KB Output is correct
22 Correct 5 ms 384 KB Output is correct
23 Correct 41 ms 1024 KB Output is correct
24 Correct 55 ms 1656 KB Output is correct
25 Correct 12 ms 384 KB Output is correct
26 Correct 36 ms 1152 KB Output is correct
27 Correct 52 ms 1400 KB Output is correct
28 Correct 59 ms 1828 KB Output is correct
29 Correct 18 ms 896 KB Output is correct
30 Correct 6 ms 384 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 36 ms 1272 KB Output is correct
2 Correct 13 ms 640 KB Output is correct
3 Correct 27 ms 896 KB Output is correct
4 Correct 26 ms 1024 KB Output is correct
5 Correct 32 ms 1272 KB Output is correct
6 Correct 23 ms 896 KB Output is correct
7 Correct 8 ms 384 KB Output is correct
8 Correct 23 ms 896 KB Output is correct
9 Correct 52 ms 1784 KB Output is correct
10 Correct 34 ms 1152 KB Output is correct
11 Correct 5 ms 256 KB Output is correct
12 Correct 5 ms 384 KB Output is correct
13 Correct 6 ms 256 KB Output is correct
14 Correct 6 ms 384 KB Output is correct
15 Correct 5 ms 384 KB Output is correct
16 Correct 5 ms 384 KB Output is correct
17 Correct 5 ms 384 KB Output is correct
18 Correct 5 ms 384 KB Output is correct
19 Correct 5 ms 384 KB Output is correct
20 Correct 5 ms 384 KB Output is correct
21 Correct 5 ms 384 KB Output is correct
22 Correct 5 ms 384 KB Output is correct
23 Correct 5 ms 384 KB Output is correct
24 Correct 5 ms 384 KB Output is correct
25 Correct 5 ms 432 KB Output is correct
26 Correct 20 ms 768 KB Output is correct
27 Correct 40 ms 1656 KB Output is correct
28 Correct 61 ms 1912 KB Output is correct
29 Correct 203 ms 1664 KB Output is correct
30 Correct 221 ms 1912 KB Output is correct
31 Correct 40 ms 1532 KB Output is correct
32 Correct 5 ms 384 KB Output is correct
33 Correct 41 ms 1024 KB Output is correct
34 Correct 55 ms 1656 KB Output is correct
35 Correct 12 ms 384 KB Output is correct
36 Correct 36 ms 1152 KB Output is correct
37 Correct 52 ms 1400 KB Output is correct
38 Correct 59 ms 1828 KB Output is correct
39 Correct 18 ms 896 KB Output is correct
40 Correct 6 ms 384 KB Output is correct
41 Correct 185 ms 1748 KB Output is correct
42 Correct 69 ms 1784 KB Output is correct
43 Correct 116 ms 1656 KB Output is correct
44 Correct 66 ms 1784 KB Output is correct
45 Correct 57 ms 1784 KB Output is correct
46 Correct 197 ms 1784 KB Output is correct
47 Correct 50 ms 1784 KB Output is correct
48 Correct 89 ms 1724 KB Output is correct
49 Correct 60 ms 1656 KB Output is correct
50 Correct 850 ms 1784 KB Output is correct
51 Correct 905 ms 1912 KB Output is correct
52 Correct 844 ms 1824 KB Output is correct
53 Correct 908 ms 1912 KB Output is correct
54 Correct 838 ms 1656 KB Output is correct
55 Correct 936 ms 1924 KB Output is correct
56 Correct 798 ms 1784 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 256 KB Output is correct
2 Correct 4 ms 256 KB Output is correct
3 Correct 5 ms 384 KB Output is correct
4 Correct 5 ms 256 KB Output is correct
5 Correct 5 ms 256 KB Output is correct
6 Correct 5 ms 256 KB Output is correct
7 Correct 4 ms 256 KB Output is correct
8 Correct 5 ms 384 KB Output is correct
9 Correct 36 ms 1272 KB Output is correct
10 Correct 13 ms 640 KB Output is correct
11 Correct 27 ms 896 KB Output is correct
12 Correct 26 ms 1024 KB Output is correct
13 Correct 32 ms 1272 KB Output is correct
14 Correct 23 ms 896 KB Output is correct
15 Correct 8 ms 384 KB Output is correct
16 Correct 23 ms 896 KB Output is correct
17 Correct 52 ms 1784 KB Output is correct
18 Correct 34 ms 1152 KB Output is correct
19 Correct 5 ms 256 KB Output is correct
20 Correct 5 ms 384 KB Output is correct
21 Correct 6 ms 256 KB Output is correct
22 Correct 6 ms 384 KB Output is correct
23 Correct 5 ms 384 KB Output is correct
24 Correct 5 ms 384 KB Output is correct
25 Correct 5 ms 384 KB Output is correct
26 Correct 5 ms 384 KB Output is correct
27 Correct 5 ms 384 KB Output is correct
28 Correct 5 ms 384 KB Output is correct
29 Correct 5 ms 384 KB Output is correct
30 Correct 5 ms 384 KB Output is correct
31 Correct 5 ms 384 KB Output is correct
32 Correct 5 ms 384 KB Output is correct
33 Correct 5 ms 432 KB Output is correct
34 Correct 20 ms 768 KB Output is correct
35 Correct 40 ms 1656 KB Output is correct
36 Correct 61 ms 1912 KB Output is correct
37 Correct 203 ms 1664 KB Output is correct
38 Correct 221 ms 1912 KB Output is correct
39 Correct 40 ms 1532 KB Output is correct
40 Correct 5 ms 384 KB Output is correct
41 Correct 41 ms 1024 KB Output is correct
42 Correct 55 ms 1656 KB Output is correct
43 Correct 12 ms 384 KB Output is correct
44 Correct 36 ms 1152 KB Output is correct
45 Correct 52 ms 1400 KB Output is correct
46 Correct 59 ms 1828 KB Output is correct
47 Correct 18 ms 896 KB Output is correct
48 Correct 6 ms 384 KB Output is correct
49 Correct 185 ms 1748 KB Output is correct
50 Correct 69 ms 1784 KB Output is correct
51 Correct 116 ms 1656 KB Output is correct
52 Correct 66 ms 1784 KB Output is correct
53 Correct 57 ms 1784 KB Output is correct
54 Correct 197 ms 1784 KB Output is correct
55 Correct 50 ms 1784 KB Output is correct
56 Correct 89 ms 1724 KB Output is correct
57 Correct 60 ms 1656 KB Output is correct
58 Correct 850 ms 1784 KB Output is correct
59 Correct 905 ms 1912 KB Output is correct
60 Correct 844 ms 1824 KB Output is correct
61 Correct 908 ms 1912 KB Output is correct
62 Correct 838 ms 1656 KB Output is correct
63 Correct 936 ms 1924 KB Output is correct
64 Correct 798 ms 1784 KB Output is correct
65 Correct 4 ms 256 KB Output is correct
66 Correct 4 ms 256 KB Output is correct
67 Correct 898 ms 1860 KB Output is correct
68 Correct 904 ms 1824 KB Output is correct
69 Correct 789 ms 1784 KB Output is correct
70 Correct 885 ms 1788 KB Output is correct
71 Correct 860 ms 1784 KB Output is correct
72 Correct 840 ms 1784 KB Output is correct
73 Correct 813 ms 1784 KB Output is correct
74 Correct 880 ms 1912 KB Output is correct
75 Correct 847 ms 1732 KB Output is correct
76 Correct 910 ms 1912 KB Output is correct
77 Correct 160 ms 1912 KB Output is correct
78 Correct 67 ms 1788 KB Output is correct
79 Correct 111 ms 1656 KB Output is correct
80 Correct 115 ms 1656 KB Output is correct
81 Correct 110 ms 1528 KB Output is correct
82 Correct 95 ms 1784 KB Output is correct
83 Correct 77 ms 1656 KB Output is correct
84 Correct 539 ms 1912 KB Output is correct
85 Correct 951 ms 1912 KB Output is correct
86 Correct 6 ms 256 KB Output is correct
87 Correct 5 ms 256 KB Output is correct
88 Correct 959 ms 2044 KB Output is correct
89 Correct 185 ms 640 KB Output is correct
90 Correct 5 ms 256 KB Output is correct