답안 #287373

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
287373 2020-08-31T16:32:28 Z Berted Chessboard (IZhO18_chessboard) C++14
100 / 100
575 ms 10524 KB
#include <iostream>
#include <vector>
#include <algorithm>
#define ll long long
#define pii pair<ll, ll>
#define fst first
#define snd second

const ll INF = 1e12;

using namespace std;

struct data
{
	ll x, y1, y2; bool t;
	inline bool operator<(const data& r) const
	{
		return make_pair(make_pair(x, y1), make_pair(y2, t)) < make_pair(make_pair(r.x, r.y1), make_pair(r.y2, r.t));
	}
};

int N, K;
ll S, p1, p2, ans = INF;
vector<data> A;

inline void a1(ll Y1, ll Y2, ll v)
{
	ll R = Y2 / (2 * S), L = Y1 / (2 * S), a = 0;
	if (L == R) {a += max(0LL, min(Y2 + 1, 2 * L * S + S) - Y1); }
	else
	{
		a += (R - L - 1) * S;
		a += max(0LL, 2 * L * S + S - Y1);
		a += min(Y2 + 1, 2 * R * S + S) - 2 * R * S;
	}
	p1 += a * v;
}

inline void a2(ll Y1, ll Y2, ll v)
{
	ll R = Y2 / (2 * S), L = Y1 / (2 * S), a = 0;
	if (L == R) {a += max(0LL, Y2 + 1 - max(Y1, 2 * L * S + S)); }
	else
	{
		a += (R - L - 1) * S;
		a += 2 * (L + 1) * S - max(Y1, 2 * L * S + S);
		a += max(0LL, Y2 + 1 - 2 * R * S - S);
	}
	p2 += a * v;
}

void solve()
{
	p1 = 0; p2 = 0;
	ll s1 = 0, s2 = 0, t1 = 0, t2 = 0; int j = 0;
	for (int i = 0; i < N; i++)
	{
		for (; j < A.size() && A[j].x <= i; j++)
		{
			if (A[j].t) 
			{
				a1(A[j].y1, A[j].y2, -1);
				a2(A[j].y1, A[j].y2, -1);
			}
			else
			{
				a1(A[j].y1, A[j].y2, 1);
				a2(A[j].y1, A[j].y2, 1);
			}
		}
		t1 += p1; t2 += p2;
		if ((i + 1) % S == 0)
		{
			ll c = (N / S + 1) / 2, f = (N / S) / 2; c *= S * S; f *= S * S;
			if (i / S % 2 == 0)
			{
				s1 += (c - t1) + t2;
				s2 += t1 + (f - t2); 
			}
			else
			{
				s2 += (c - t1) + t2;
				s1 += t1 + (f - t2); 
			}
			t1 = 0; t2 = 0;
		}
	}
	ans = min(ans, min(s1, s2));
}

int main()
{
	ios :: sync_with_stdio(0); cin.tie(0); cout.tie(0);
	cin >> N >> K;
	for (int i = 0; i < K; i++)
	{
		int x1, y1, x2, y2; cin >> x1 >> y1 >> x2 >> y2;
		data a; a.x = x1 - 1; a.y1 = y1 - 1; a.y2 = y2 - 1; a.t = 0;
		data b; b.x = x2; b.y1 = y1 - 1; b.y2 = y2 - 1; b.t = 1;
		A.push_back(a); A.push_back(b);
	}
	sort(A.begin(), A.end());
	for (int i = 1; i * i <= N; i++)
	{
		if (N % i == 0)
		{
			S = i; solve();
			if (i * i < N && i > 1) {S = N / i; solve();}
		}
	}
	cout << ans << "\n";
	return 0;
}

Compilation message

chessboard.cpp: In function 'void solve()':
chessboard.cpp:58:12: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<data>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   58 |   for (; j < A.size() && A[j].x <= i; j++)
      |          ~~^~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 384 KB Output is correct
2 Correct 1 ms 384 KB Output is correct
3 Correct 1 ms 384 KB Output is correct
4 Correct 1 ms 384 KB Output is correct
5 Correct 1 ms 384 KB Output is correct
6 Correct 1 ms 384 KB Output is correct
7 Correct 1 ms 384 KB Output is correct
8 Correct 1 ms 384 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 50 ms 5224 KB Output is correct
2 Correct 14 ms 2936 KB Output is correct
3 Correct 31 ms 5492 KB Output is correct
4 Correct 38 ms 5364 KB Output is correct
5 Correct 43 ms 5620 KB Output is correct
6 Correct 28 ms 5364 KB Output is correct
7 Correct 6 ms 1152 KB Output is correct
8 Correct 29 ms 5364 KB Output is correct
9 Correct 81 ms 10336 KB Output is correct
10 Correct 46 ms 5620 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 1 ms 384 KB Output is correct
3 Correct 1 ms 384 KB Output is correct
4 Correct 2 ms 512 KB Output is correct
5 Correct 1 ms 512 KB Output is correct
6 Correct 1 ms 384 KB Output is correct
7 Correct 1 ms 512 KB Output is correct
8 Correct 1 ms 512 KB Output is correct
9 Correct 1 ms 384 KB Output is correct
10 Correct 1 ms 384 KB Output is correct
11 Correct 1 ms 384 KB Output is correct
12 Correct 1 ms 384 KB Output is correct
13 Correct 2 ms 512 KB Output is correct
14 Correct 1 ms 512 KB Output is correct
15 Correct 1 ms 512 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 1 ms 384 KB Output is correct
3 Correct 1 ms 384 KB Output is correct
4 Correct 2 ms 512 KB Output is correct
5 Correct 1 ms 512 KB Output is correct
6 Correct 1 ms 384 KB Output is correct
7 Correct 1 ms 512 KB Output is correct
8 Correct 1 ms 512 KB Output is correct
9 Correct 1 ms 384 KB Output is correct
10 Correct 1 ms 384 KB Output is correct
11 Correct 1 ms 384 KB Output is correct
12 Correct 1 ms 384 KB Output is correct
13 Correct 2 ms 512 KB Output is correct
14 Correct 1 ms 512 KB Output is correct
15 Correct 1 ms 512 KB Output is correct
16 Correct 20 ms 2936 KB Output is correct
17 Correct 59 ms 9968 KB Output is correct
18 Correct 92 ms 9956 KB Output is correct
19 Correct 128 ms 9960 KB Output is correct
20 Correct 130 ms 9960 KB Output is correct
21 Correct 61 ms 9968 KB Output is correct
22 Correct 1 ms 384 KB Output is correct
23 Correct 35 ms 5236 KB Output is correct
24 Correct 68 ms 9956 KB Output is correct
25 Correct 11 ms 1660 KB Output is correct
26 Correct 43 ms 5364 KB Output is correct
27 Correct 61 ms 9828 KB Output is correct
28 Correct 74 ms 9984 KB Output is correct
29 Correct 26 ms 5100 KB Output is correct
30 Correct 3 ms 768 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 50 ms 5224 KB Output is correct
2 Correct 14 ms 2936 KB Output is correct
3 Correct 31 ms 5492 KB Output is correct
4 Correct 38 ms 5364 KB Output is correct
5 Correct 43 ms 5620 KB Output is correct
6 Correct 28 ms 5364 KB Output is correct
7 Correct 6 ms 1152 KB Output is correct
8 Correct 29 ms 5364 KB Output is correct
9 Correct 81 ms 10336 KB Output is correct
10 Correct 46 ms 5620 KB Output is correct
11 Correct 1 ms 384 KB Output is correct
12 Correct 1 ms 384 KB Output is correct
13 Correct 1 ms 384 KB Output is correct
14 Correct 2 ms 512 KB Output is correct
15 Correct 1 ms 512 KB Output is correct
16 Correct 1 ms 384 KB Output is correct
17 Correct 1 ms 512 KB Output is correct
18 Correct 1 ms 512 KB Output is correct
19 Correct 1 ms 384 KB Output is correct
20 Correct 1 ms 384 KB Output is correct
21 Correct 1 ms 384 KB Output is correct
22 Correct 1 ms 384 KB Output is correct
23 Correct 2 ms 512 KB Output is correct
24 Correct 1 ms 512 KB Output is correct
25 Correct 1 ms 512 KB Output is correct
26 Correct 20 ms 2936 KB Output is correct
27 Correct 59 ms 9968 KB Output is correct
28 Correct 92 ms 9956 KB Output is correct
29 Correct 128 ms 9960 KB Output is correct
30 Correct 130 ms 9960 KB Output is correct
31 Correct 61 ms 9968 KB Output is correct
32 Correct 1 ms 384 KB Output is correct
33 Correct 35 ms 5236 KB Output is correct
34 Correct 68 ms 9956 KB Output is correct
35 Correct 11 ms 1660 KB Output is correct
36 Correct 43 ms 5364 KB Output is correct
37 Correct 61 ms 9828 KB Output is correct
38 Correct 74 ms 9984 KB Output is correct
39 Correct 26 ms 5100 KB Output is correct
40 Correct 3 ms 768 KB Output is correct
41 Correct 132 ms 10516 KB Output is correct
42 Correct 96 ms 10448 KB Output is correct
43 Correct 114 ms 10460 KB Output is correct
44 Correct 86 ms 10512 KB Output is correct
45 Correct 88 ms 10444 KB Output is correct
46 Correct 163 ms 10464 KB Output is correct
47 Correct 81 ms 10468 KB Output is correct
48 Correct 87 ms 10488 KB Output is correct
49 Correct 71 ms 10464 KB Output is correct
50 Correct 448 ms 10468 KB Output is correct
51 Correct 468 ms 10480 KB Output is correct
52 Correct 455 ms 10472 KB Output is correct
53 Correct 521 ms 10524 KB Output is correct
54 Correct 461 ms 10460 KB Output is correct
55 Correct 541 ms 10472 KB Output is correct
56 Correct 449 ms 10468 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 384 KB Output is correct
2 Correct 1 ms 384 KB Output is correct
3 Correct 1 ms 384 KB Output is correct
4 Correct 1 ms 384 KB Output is correct
5 Correct 1 ms 384 KB Output is correct
6 Correct 1 ms 384 KB Output is correct
7 Correct 1 ms 384 KB Output is correct
8 Correct 1 ms 384 KB Output is correct
9 Correct 50 ms 5224 KB Output is correct
10 Correct 14 ms 2936 KB Output is correct
11 Correct 31 ms 5492 KB Output is correct
12 Correct 38 ms 5364 KB Output is correct
13 Correct 43 ms 5620 KB Output is correct
14 Correct 28 ms 5364 KB Output is correct
15 Correct 6 ms 1152 KB Output is correct
16 Correct 29 ms 5364 KB Output is correct
17 Correct 81 ms 10336 KB Output is correct
18 Correct 46 ms 5620 KB Output is correct
19 Correct 1 ms 384 KB Output is correct
20 Correct 1 ms 384 KB Output is correct
21 Correct 1 ms 384 KB Output is correct
22 Correct 2 ms 512 KB Output is correct
23 Correct 1 ms 512 KB Output is correct
24 Correct 1 ms 384 KB Output is correct
25 Correct 1 ms 512 KB Output is correct
26 Correct 1 ms 512 KB Output is correct
27 Correct 1 ms 384 KB Output is correct
28 Correct 1 ms 384 KB Output is correct
29 Correct 1 ms 384 KB Output is correct
30 Correct 1 ms 384 KB Output is correct
31 Correct 2 ms 512 KB Output is correct
32 Correct 1 ms 512 KB Output is correct
33 Correct 1 ms 512 KB Output is correct
34 Correct 20 ms 2936 KB Output is correct
35 Correct 59 ms 9968 KB Output is correct
36 Correct 92 ms 9956 KB Output is correct
37 Correct 128 ms 9960 KB Output is correct
38 Correct 130 ms 9960 KB Output is correct
39 Correct 61 ms 9968 KB Output is correct
40 Correct 1 ms 384 KB Output is correct
41 Correct 35 ms 5236 KB Output is correct
42 Correct 68 ms 9956 KB Output is correct
43 Correct 11 ms 1660 KB Output is correct
44 Correct 43 ms 5364 KB Output is correct
45 Correct 61 ms 9828 KB Output is correct
46 Correct 74 ms 9984 KB Output is correct
47 Correct 26 ms 5100 KB Output is correct
48 Correct 3 ms 768 KB Output is correct
49 Correct 132 ms 10516 KB Output is correct
50 Correct 96 ms 10448 KB Output is correct
51 Correct 114 ms 10460 KB Output is correct
52 Correct 86 ms 10512 KB Output is correct
53 Correct 88 ms 10444 KB Output is correct
54 Correct 163 ms 10464 KB Output is correct
55 Correct 81 ms 10468 KB Output is correct
56 Correct 87 ms 10488 KB Output is correct
57 Correct 71 ms 10464 KB Output is correct
58 Correct 448 ms 10468 KB Output is correct
59 Correct 468 ms 10480 KB Output is correct
60 Correct 455 ms 10472 KB Output is correct
61 Correct 521 ms 10524 KB Output is correct
62 Correct 461 ms 10460 KB Output is correct
63 Correct 541 ms 10472 KB Output is correct
64 Correct 449 ms 10468 KB Output is correct
65 Correct 1 ms 384 KB Output is correct
66 Correct 0 ms 384 KB Output is correct
67 Correct 522 ms 10464 KB Output is correct
68 Correct 526 ms 10464 KB Output is correct
69 Correct 443 ms 10468 KB Output is correct
70 Correct 506 ms 10472 KB Output is correct
71 Correct 493 ms 10488 KB Output is correct
72 Correct 462 ms 10472 KB Output is correct
73 Correct 472 ms 10456 KB Output is correct
74 Correct 488 ms 10468 KB Output is correct
75 Correct 483 ms 10496 KB Output is correct
76 Correct 531 ms 10472 KB Output is correct
77 Correct 129 ms 10468 KB Output is correct
78 Correct 79 ms 10340 KB Output is correct
79 Correct 113 ms 10448 KB Output is correct
80 Correct 127 ms 10464 KB Output is correct
81 Correct 104 ms 10480 KB Output is correct
82 Correct 112 ms 10468 KB Output is correct
83 Correct 85 ms 10468 KB Output is correct
84 Correct 334 ms 10468 KB Output is correct
85 Correct 518 ms 10312 KB Output is correct
86 Correct 78 ms 384 KB Output is correct
87 Correct 77 ms 384 KB Output is correct
88 Correct 575 ms 10468 KB Output is correct
89 Correct 187 ms 2928 KB Output is correct
90 Correct 76 ms 384 KB Output is correct