답안 #555263

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
555263 2022-04-30T10:49:04 Z ngpin04 Chessboard (IZhO18_chessboard) C++14
70 / 100
935 ms 1888 KB
#include <bits/stdc++.h>
#define fi first
#define se second
#define mp make_pair
#define TASK ""
#define ALL(x) (x).begin(), (x).end() 
using namespace std;
template <typename T1, typename T2> bool mini(T1 &a, T2 b) {
	if (a > b) {a = b; return true;} return false;
}
template <typename T1, typename T2> bool maxi(T1 &a, T2 b) {
	if (a < b) {a = b; return true;} return false;
}
const int N = 1e5 + 5; 
const int oo = 1e9;
const long long ooo = 1e18;
const int mod = 1e9 + 7; // 998244353;
const long double pi = acos(-1);

pair <int, int> a[N], b[N];

int n,k;

int getc(int i, int j, int l, int val) {
	return (((i / l) ^ (j / l)) & 1) ^ val;
}

int getv(int i, int j, int l, int val) {
	return (getc(i, j, l, val) > 0) ? -1 : 1;
}

long long calc(int x, int y, int u, int v, int l, int val) {
	if (x > u || y > v)
		return 0;

	long long res = 0;
	int dx = (u - x + 1);
	int dy = (v - y + 1);
	if (dx > dy)
		swap(dx, dy);

	if (dx < l) {
		if (dy < l) 
			res = (long long) dx * dy * getv(x, y, l, val);
		else {
			if ((dy / l) & 1)
				res = (long long) dx * l * getv(x, y, l, val); 
		}
	} else {
		if ((dx / l) & (dy / l) & 1)
			res = (long long) l * l * getv(x, y, l, val);
	}
	return res;
}

int main() {
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	#ifdef ONLINE_JUDGE
	// freopen(TASK".inp","r",stdin);
	// freopen(TASK".out","w",stdout);
	#endif
	cin >> n >> k;
	if (n <= 100 && k == 0) {
		int ans = oo;
		for (int i = 1; i < n; i++) if (n % i == 0) {
			int d = (n / i);
			mini(ans, ((d * d) >> 1) * i * i);
			// cerr << d << " " << i << "\n";
		}
		cout << ans << "\n";
		return 0;
	}

	for (int i = 1; i <= k; i++) {
		cin >> a[i].fi >> a[i].se >> b[i].fi >> b[i].se;
		a[i].fi--; a[i].se--;
		b[i].fi--; b[i].se--;
	}

	long long ans = ooo;
	for (int l = 1; l < n; l++) if (n % l == 0) 
	for (int val = 0; val < 2; val++) {
		int d = (n / l);
		long long res = ((1LL * d * d + val) >> 1) * l * l;
		for (int id = 1; id <= k; id++) {
			int x = a[id].fi;
			int y = a[id].se;
			int u = b[id].fi;
			int v = b[id].se;

			int i = (x + l - 1) / l * l;
			int j = (y + l - 1) / l * l;
			int s = (u + 1) / l * l - 1;
			int t = (v + 1) / l * l - 1;
			if (i > s || j > t) {
				res += (long long) getv(x, y, l, val) * 
				(u - x + 1) * (v - y + 1);
			} else {
				// cerr << i << " " << j << " " << s << " " << t << "\n";
				vector <pair <int, int>> r, c;
				r.push_back(mp(x, i - 1));
				r.push_back(mp(i, s));
				r.push_back(mp(s + 1, u));
				c.push_back(mp(y, j - 1));
				c.push_back(mp(j, t));
				c.push_back(mp(t + 1, v));
				for (pair <int, int> a : r)
				for (pair <int, int> b : c)
					res += calc(a.fi, b.fi, a.se, b.se, l, val);
			}
		}
		// cerr << "split: " << l << " " << val << " " << res << "\n";
		mini(ans, res);
	}

	cout << ans;
	return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 0 ms 328 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 46 ms 1292 KB Output is correct
2 Correct 11 ms 596 KB Output is correct
3 Correct 26 ms 956 KB Output is correct
4 Correct 31 ms 1028 KB Output is correct
5 Correct 38 ms 1112 KB Output is correct
6 Correct 24 ms 752 KB Output is correct
7 Correct 5 ms 340 KB Output is correct
8 Correct 23 ms 884 KB Output is correct
9 Correct 60 ms 1680 KB Output is correct
10 Correct 35 ms 1092 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 1 ms 340 KB Output is correct
12 Correct 1 ms 456 KB Output is correct
13 Correct 1 ms 340 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
15 Correct 1 ms 340 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 1 ms 340 KB Output is correct
12 Correct 1 ms 456 KB Output is correct
13 Correct 1 ms 340 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
15 Correct 1 ms 340 KB Output is correct
16 Correct 20 ms 760 KB Output is correct
17 Correct 49 ms 1564 KB Output is correct
18 Correct 73 ms 1888 KB Output is correct
19 Correct 195 ms 1688 KB Output is correct
20 Correct 220 ms 1748 KB Output is correct
21 Correct 52 ms 1492 KB Output is correct
22 Correct 1 ms 336 KB Output is correct
23 Correct 43 ms 1100 KB Output is correct
24 Correct 67 ms 1660 KB Output is correct
25 Correct 9 ms 464 KB Output is correct
26 Correct 41 ms 1156 KB Output is correct
27 Correct 58 ms 1376 KB Output is correct
28 Correct 69 ms 1748 KB Output is correct
29 Correct 20 ms 776 KB Output is correct
30 Correct 3 ms 340 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 46 ms 1292 KB Output is correct
2 Correct 11 ms 596 KB Output is correct
3 Correct 26 ms 956 KB Output is correct
4 Correct 31 ms 1028 KB Output is correct
5 Correct 38 ms 1112 KB Output is correct
6 Correct 24 ms 752 KB Output is correct
7 Correct 5 ms 340 KB Output is correct
8 Correct 23 ms 884 KB Output is correct
9 Correct 60 ms 1680 KB Output is correct
10 Correct 35 ms 1092 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Correct 0 ms 212 KB Output is correct
13 Correct 1 ms 340 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
15 Correct 1 ms 340 KB Output is correct
16 Correct 1 ms 340 KB Output is correct
17 Correct 1 ms 340 KB Output is correct
18 Correct 1 ms 340 KB Output is correct
19 Correct 1 ms 212 KB Output is correct
20 Correct 1 ms 212 KB Output is correct
21 Correct 1 ms 340 KB Output is correct
22 Correct 1 ms 456 KB Output is correct
23 Correct 1 ms 340 KB Output is correct
24 Correct 1 ms 340 KB Output is correct
25 Correct 1 ms 340 KB Output is correct
26 Correct 20 ms 760 KB Output is correct
27 Correct 49 ms 1564 KB Output is correct
28 Correct 73 ms 1888 KB Output is correct
29 Correct 195 ms 1688 KB Output is correct
30 Correct 220 ms 1748 KB Output is correct
31 Correct 52 ms 1492 KB Output is correct
32 Correct 1 ms 336 KB Output is correct
33 Correct 43 ms 1100 KB Output is correct
34 Correct 67 ms 1660 KB Output is correct
35 Correct 9 ms 464 KB Output is correct
36 Correct 41 ms 1156 KB Output is correct
37 Correct 58 ms 1376 KB Output is correct
38 Correct 69 ms 1748 KB Output is correct
39 Correct 20 ms 776 KB Output is correct
40 Correct 3 ms 340 KB Output is correct
41 Correct 182 ms 1500 KB Output is correct
42 Correct 82 ms 1780 KB Output is correct
43 Correct 115 ms 1628 KB Output is correct
44 Correct 74 ms 1732 KB Output is correct
45 Correct 65 ms 1840 KB Output is correct
46 Correct 203 ms 1764 KB Output is correct
47 Correct 56 ms 1644 KB Output is correct
48 Correct 102 ms 1648 KB Output is correct
49 Correct 68 ms 1624 KB Output is correct
50 Correct 842 ms 1728 KB Output is correct
51 Correct 907 ms 1828 KB Output is correct
52 Correct 842 ms 1716 KB Output is correct
53 Correct 886 ms 1808 KB Output is correct
54 Correct 831 ms 1708 KB Output is correct
55 Correct 935 ms 1876 KB Output is correct
56 Correct 804 ms 1648 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 0 ms 328 KB Output is correct
9 Correct 46 ms 1292 KB Output is correct
10 Correct 11 ms 596 KB Output is correct
11 Correct 26 ms 956 KB Output is correct
12 Correct 31 ms 1028 KB Output is correct
13 Correct 38 ms 1112 KB Output is correct
14 Correct 24 ms 752 KB Output is correct
15 Correct 5 ms 340 KB Output is correct
16 Correct 23 ms 884 KB Output is correct
17 Correct 60 ms 1680 KB Output is correct
18 Correct 35 ms 1092 KB Output is correct
19 Correct 1 ms 212 KB Output is correct
20 Correct 0 ms 212 KB Output is correct
21 Correct 1 ms 340 KB Output is correct
22 Correct 1 ms 340 KB Output is correct
23 Correct 1 ms 340 KB Output is correct
24 Correct 1 ms 340 KB Output is correct
25 Correct 1 ms 340 KB Output is correct
26 Correct 1 ms 340 KB Output is correct
27 Correct 1 ms 212 KB Output is correct
28 Correct 1 ms 212 KB Output is correct
29 Correct 1 ms 340 KB Output is correct
30 Correct 1 ms 456 KB Output is correct
31 Correct 1 ms 340 KB Output is correct
32 Correct 1 ms 340 KB Output is correct
33 Correct 1 ms 340 KB Output is correct
34 Correct 20 ms 760 KB Output is correct
35 Correct 49 ms 1564 KB Output is correct
36 Correct 73 ms 1888 KB Output is correct
37 Correct 195 ms 1688 KB Output is correct
38 Correct 220 ms 1748 KB Output is correct
39 Correct 52 ms 1492 KB Output is correct
40 Correct 1 ms 336 KB Output is correct
41 Correct 43 ms 1100 KB Output is correct
42 Correct 67 ms 1660 KB Output is correct
43 Correct 9 ms 464 KB Output is correct
44 Correct 41 ms 1156 KB Output is correct
45 Correct 58 ms 1376 KB Output is correct
46 Correct 69 ms 1748 KB Output is correct
47 Correct 20 ms 776 KB Output is correct
48 Correct 3 ms 340 KB Output is correct
49 Correct 182 ms 1500 KB Output is correct
50 Correct 82 ms 1780 KB Output is correct
51 Correct 115 ms 1628 KB Output is correct
52 Correct 74 ms 1732 KB Output is correct
53 Correct 65 ms 1840 KB Output is correct
54 Correct 203 ms 1764 KB Output is correct
55 Correct 56 ms 1644 KB Output is correct
56 Correct 102 ms 1648 KB Output is correct
57 Correct 68 ms 1624 KB Output is correct
58 Correct 842 ms 1728 KB Output is correct
59 Correct 907 ms 1828 KB Output is correct
60 Correct 842 ms 1716 KB Output is correct
61 Correct 886 ms 1808 KB Output is correct
62 Correct 831 ms 1708 KB Output is correct
63 Correct 935 ms 1876 KB Output is correct
64 Correct 804 ms 1648 KB Output is correct
65 Correct 1 ms 212 KB Output is correct
66 Incorrect 0 ms 212 KB Output isn't correct
67 Halted 0 ms 0 KB -