답안 #213343

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
213343 2020-03-25T16:04:33 Z quocnguyen1012 Chessboard (IZhO18_chessboard) C++14
100 / 100
840 ms 5884 KB
#include <bits/stdc++.h>

#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define eb emplace_back
#define int long long

using namespace std;
typedef long long ll;
typedef pair<int, int> ii;

int N, K;
vector<pair<ii, ii>> rect;
ll res = 1e18;

ll sub(int d, int x, int y)
{
  int X = x / d;
  int Y = y / d;
  ll ret = 0;
  if(X % 2 == 0 || Y % 2 == 0)
    ret += 1ll * X * Y / 2 * d * d;
  else
    ret += (1ll * X * Y / 2 + 1) * d * d;
  if (X % 2 == Y % 2) {
		ret += (ll) (x - X * d) * (y - Y * d);
	}
	if (Y % 2 == 0) {
		ret += (ll) (X + 1) / 2 * (y - Y * d) * d;
	}
	else {
		ret += (ll) X / 2 * (y - Y * d) * d;
	}
	if (X % 2 == 0) {
		ret += (ll) (Y + 1) / 2 * (x - X * d) * d;
	}
	else {
		ret += (ll) Y / 2 * (x - X * d) * d;
	}
	return ret;
}

void solve(int d)
{
  ll sum = 0, rem = 0;
  for(auto & all : rect){
    sum += sub(d, all.se.fi, all.se.se) + sub(d, all.fi.fi - 1, all.fi.se - 1)
            - sub(d, all.fi.fi - 1, all.se.se) - sub(d, all.se.fi, all.fi.se - 1);
    rem += 1ll * (all.se.se - all.fi.se + 1) * (all.se.fi - all.fi.fi + 1);
  }
  ll black = sub(d, N, N);
  ll white = N * N - black;
  res = min(res, black + rem - 2 * sum);
  res = min(res, white - rem + 2 * sum);
}

signed main(void)
{
  ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
  #ifdef LOCAL
    freopen("A.INP", "r", stdin);
    freopen("A.OUT", "w", stdout);
  #endif // LOCAL
  cin >> N >> K;
  rect.resize(K);
  for(auto & x : rect) cin >> x.fi.fi >> x.fi.se >> x.se.fi >> x.se.se;
  for(int i = 1; i < N; ++i){
    if(N % i == 0) solve(i);
  }
  cout << res;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 384 KB Output is correct
2 Correct 5 ms 384 KB Output is correct
3 Correct 6 ms 384 KB Output is correct
4 Correct 5 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
# 결과 실행 시간 메모리 Grader output
1 Correct 36 ms 2304 KB Output is correct
2 Correct 11 ms 1280 KB Output is correct
3 Correct 24 ms 2560 KB Output is correct
4 Correct 24 ms 2688 KB Output is correct
5 Correct 32 ms 3324 KB Output is correct
6 Correct 22 ms 2304 KB Output is correct
7 Correct 9 ms 768 KB Output is correct
8 Correct 22 ms 2304 KB Output is correct
9 Correct 47 ms 5240 KB Output is correct
10 Correct 29 ms 3200 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 384 KB Output is correct
2 Correct 5 ms 384 KB Output is correct
3 Correct 5 ms 384 KB Output is correct
4 Correct 5 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 384 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 384 KB Output is correct
2 Correct 5 ms 384 KB Output is correct
3 Correct 5 ms 384 KB Output is correct
4 Correct 5 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 384 KB Output is correct
16 Correct 18 ms 1280 KB Output is correct
17 Correct 37 ms 2944 KB Output is correct
18 Correct 50 ms 3456 KB Output is correct
19 Correct 184 ms 3072 KB Output is correct
20 Correct 187 ms 3456 KB Output is correct
21 Correct 32 ms 2944 KB Output is correct
22 Correct 5 ms 384 KB Output is correct
23 Correct 34 ms 1664 KB Output is correct
24 Correct 46 ms 3328 KB Output is correct
25 Correct 10 ms 640 KB Output is correct
26 Correct 32 ms 2176 KB Output is correct
27 Correct 45 ms 2560 KB Output is correct
28 Correct 49 ms 3328 KB Output is correct
29 Correct 16 ms 1408 KB Output is correct
30 Correct 6 ms 512 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 36 ms 2304 KB Output is correct
2 Correct 11 ms 1280 KB Output is correct
3 Correct 24 ms 2560 KB Output is correct
4 Correct 24 ms 2688 KB Output is correct
5 Correct 32 ms 3324 KB Output is correct
6 Correct 22 ms 2304 KB Output is correct
7 Correct 9 ms 768 KB Output is correct
8 Correct 22 ms 2304 KB Output is correct
9 Correct 47 ms 5240 KB Output is correct
10 Correct 29 ms 3200 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 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 384 KB Output is correct
26 Correct 18 ms 1280 KB Output is correct
27 Correct 37 ms 2944 KB Output is correct
28 Correct 50 ms 3456 KB Output is correct
29 Correct 184 ms 3072 KB Output is correct
30 Correct 187 ms 3456 KB Output is correct
31 Correct 32 ms 2944 KB Output is correct
32 Correct 5 ms 384 KB Output is correct
33 Correct 34 ms 1664 KB Output is correct
34 Correct 46 ms 3328 KB Output is correct
35 Correct 10 ms 640 KB Output is correct
36 Correct 32 ms 2176 KB Output is correct
37 Correct 45 ms 2560 KB Output is correct
38 Correct 49 ms 3328 KB Output is correct
39 Correct 16 ms 1408 KB Output is correct
40 Correct 6 ms 512 KB Output is correct
41 Correct 165 ms 4984 KB Output is correct
42 Correct 62 ms 5624 KB Output is correct
43 Correct 96 ms 4984 KB Output is correct
44 Correct 60 ms 5376 KB Output is correct
45 Correct 52 ms 5760 KB Output is correct
46 Correct 178 ms 5496 KB Output is correct
47 Correct 48 ms 5112 KB Output is correct
48 Correct 80 ms 5248 KB Output is correct
49 Correct 56 ms 4984 KB Output is correct
50 Correct 754 ms 5368 KB Output is correct
51 Correct 799 ms 5752 KB Output is correct
52 Correct 744 ms 5368 KB Output is correct
53 Correct 797 ms 5624 KB Output is correct
54 Correct 740 ms 5240 KB Output is correct
55 Correct 826 ms 5880 KB Output is correct
56 Correct 709 ms 5120 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 384 KB Output is correct
2 Correct 5 ms 384 KB Output is correct
3 Correct 6 ms 384 KB Output is correct
4 Correct 5 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 36 ms 2304 KB Output is correct
10 Correct 11 ms 1280 KB Output is correct
11 Correct 24 ms 2560 KB Output is correct
12 Correct 24 ms 2688 KB Output is correct
13 Correct 32 ms 3324 KB Output is correct
14 Correct 22 ms 2304 KB Output is correct
15 Correct 9 ms 768 KB Output is correct
16 Correct 22 ms 2304 KB Output is correct
17 Correct 47 ms 5240 KB Output is correct
18 Correct 29 ms 3200 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 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 384 KB Output is correct
34 Correct 18 ms 1280 KB Output is correct
35 Correct 37 ms 2944 KB Output is correct
36 Correct 50 ms 3456 KB Output is correct
37 Correct 184 ms 3072 KB Output is correct
38 Correct 187 ms 3456 KB Output is correct
39 Correct 32 ms 2944 KB Output is correct
40 Correct 5 ms 384 KB Output is correct
41 Correct 34 ms 1664 KB Output is correct
42 Correct 46 ms 3328 KB Output is correct
43 Correct 10 ms 640 KB Output is correct
44 Correct 32 ms 2176 KB Output is correct
45 Correct 45 ms 2560 KB Output is correct
46 Correct 49 ms 3328 KB Output is correct
47 Correct 16 ms 1408 KB Output is correct
48 Correct 6 ms 512 KB Output is correct
49 Correct 165 ms 4984 KB Output is correct
50 Correct 62 ms 5624 KB Output is correct
51 Correct 96 ms 4984 KB Output is correct
52 Correct 60 ms 5376 KB Output is correct
53 Correct 52 ms 5760 KB Output is correct
54 Correct 178 ms 5496 KB Output is correct
55 Correct 48 ms 5112 KB Output is correct
56 Correct 80 ms 5248 KB Output is correct
57 Correct 56 ms 4984 KB Output is correct
58 Correct 754 ms 5368 KB Output is correct
59 Correct 799 ms 5752 KB Output is correct
60 Correct 744 ms 5368 KB Output is correct
61 Correct 797 ms 5624 KB Output is correct
62 Correct 740 ms 5240 KB Output is correct
63 Correct 826 ms 5880 KB Output is correct
64 Correct 709 ms 5120 KB Output is correct
65 Correct 5 ms 384 KB Output is correct
66 Correct 5 ms 512 KB Output is correct
67 Correct 784 ms 5496 KB Output is correct
68 Correct 780 ms 5496 KB Output is correct
69 Correct 684 ms 4860 KB Output is correct
70 Correct 762 ms 5368 KB Output is correct
71 Correct 748 ms 5240 KB Output is correct
72 Correct 732 ms 5244 KB Output is correct
73 Correct 721 ms 5112 KB Output is correct
74 Correct 772 ms 5496 KB Output is correct
75 Correct 750 ms 5240 KB Output is correct
76 Correct 793 ms 5624 KB Output is correct
77 Correct 142 ms 5880 KB Output is correct
78 Correct 59 ms 5332 KB Output is correct
79 Correct 101 ms 5112 KB Output is correct
80 Correct 105 ms 5240 KB Output is correct
81 Correct 99 ms 4864 KB Output is correct
82 Correct 85 ms 5624 KB Output is correct
83 Correct 71 ms 5112 KB Output is correct
84 Correct 476 ms 5752 KB Output is correct
85 Correct 821 ms 5752 KB Output is correct
86 Correct 6 ms 384 KB Output is correct
87 Correct 5 ms 384 KB Output is correct
88 Correct 840 ms 5884 KB Output is correct
89 Correct 163 ms 1408 KB Output is correct
90 Correct 5 ms 384 KB Output is correct