Submission #378866

# Submission time Handle Problem Language Result Execution time Memory
378866 2021-03-17T06:45:49 Z hhhhaura Chessboard (IZhO18_chessboard) C++14
100 / 100
620 ms 5868 KB
#define wiwihorz
#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
#pragma loop-opt(on)

#define rep(i, a, b) for(int i = a; i <= b; i++)
#define rrep(i, a, b) for(int i = b; i >= a; i--)
#define ceil(a, b) ((a + b - 1) / (b))
#define all(x) x.begin(), x.end()

#define INF 1000000000000000000
#define MOD 1000000007
#define eps (1e-9)
#define MAXN 1000005

#define int long long int
#define lld long double
#define pii pair<int, int>
#define random mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count())

using namespace std;
#ifdef wiwihorz
#define print(a...) kout("[" + string(#a) + "] = ", a)
void vprint(auto L, auto R) {
	while(L < R) cerr << *L << " \n"[next(L) == R], ++ L;
}
void kout() {cerr << endl;}
template<class T1, class ... T2> void kout(T1 a, T2 ... e) {
	cerr << a << " ", kout(e...);
}
#else 
#define print(...) 0
#define vprint(...) 0
#endif
struct sb2 {
	int n, k;
	struct pt {
		int u, l, d, r;
	};
	vector<pt> a;
	void init_(int _n, int _k) {
		n = _n, k = _k;
		a.assign(k + 1, {0, 0, 0, 0});
	}
	int solve() {
		int ans[2];
		ans[0] = ans[1] = 0;
		rep(i, 1, k) {
			int x, y;
			x = a[i].u, y = a[i].l;
			if((x & 1) == (y & 1)) ans[0] ++;
			else ans[1] ++;
		}
		int cnt1 = ceil(n, 2) * ceil(n, 2) + (n / 2) * (n / 2);
		int aa = cnt1 - ans[0] + ans[1];
		int bb = n * n - cnt1 - ans[1] + ans[0];
		return min(aa, bb);
	}

} ;
struct sb1 {
	int n, k;
	struct pt {
		int u, l, d, r;
	};
	vector<pt> a;
	void init_(int _n, int _k) {
		n = _n, k = _k;
		a.assign(k + 1, {0, 0, 0, 0});
	}
	int solve() {
		int ans = INF;
		rep(i, 1, n - 1) {
			if(n % i) continue;
			int cnt = 0;
			rep(j, 1, n / i) rep(m, 1, n / i) {
				cnt += i * i * bool((j & 1) == (m & 1));
			}
			ans = min(ans, n * n - cnt);
		}
		return ans;
	}

} ;
struct sb3 {
	int n, k;
	struct pt {
		int u, l, d, r;
	};
	vector<pt> a;
	void init_(int _n, int _k) {
		n = _n, k = _k;
		a.assign(k + 1, {0, 0, 0, 0});
	}
	int get(int x) {
		return ceil(x, 2) * ceil(x, 2) + (x / 2) * (x / 2);
	}
	int cal(int x) {
		assert(n % x == 0);
		int ans[2]; ans[0] = 0, ans[1] = 0;
		rep(i, 1, k) {
			int u = a[i].u, l = a[i].l;
			int uu = ceil(u, x) & 1, ll = ceil(l, x) & 1;
			ans[(uu == ll)] ++;
		}
		int cc = get(n / x);
		int cnt1 = x * x * cc + ans[0] - ans[1];
		int cnt2 = ((n / x) * (n / x) - cc) * x * x + ans[1] - ans[0];
		print(x, cnt1, cnt2, ans[0], ans[1]);
		return min(cnt1, cnt2);
	}
	int solve() {
		int kk = sqrt(n) + 1, ans = INF;
		rep(i, 1, kk) {
			if(n % i) continue;
			if(i != n) ans = min(ans, cal(i));
			if(n / i != n)ans = min(ans, cal(n / i));
		}
		return ans;
	}

} ;
struct sb4 {
	int n, k;
	struct pt {
		int u, l, d, r;
	};
	vector<pt> a;
	void init_(int _n, int _k) {
		n = _n, k = _k;
		a.assign(k + 1, {0, 0, 0, 0});
	}
	int get(int x) {
		return ceil(x, 2) * ceil(x, 2) + (x / 2) * (x / 2);
	}
	int pre(int x, int y, int v) {
		int ans = 0, xx = ceil(x, v) - 1, yy = ceil(y, v) - 1;
		if(x == 0 || y == 0) return 0;
		ans += ceil(xx, 2) * ceil(yy, 2) * v * v + (xx / 2) * (yy / 2) * v * v;
		// down
		if(xx & 1) ans += (yy / 2) * (x - xx * v) * v;
		else ans += ceil(yy , 2) * (x - xx * v) * v;
		// right
		if(yy & 1) ans += (xx / 2) * (y - yy * v) * v;
		else ans += ceil(xx, 2) * (y - yy * v) * v;
		// r0d
		if((xx & 1) == (yy & 1)) ans += (x - xx * v) * (y - yy * v);

		return ans;
	} 
	int val(int u, int d, int l, int r, int v) {
		int ans = pre(d, r, v) - pre(d, l - 1, v) 
			- pre(u - 1, r, v) + pre(u - 1, l - 1, v);
//		print(u, d, l, r, v, ans);
		return ans;
	}
	int cal(int x) {
		assert(n % x == 0);
		int ans[2]; ans[0] = 0, ans[1] = 0;
		rep(i, 1, k) {
			int u = a[i].u, l = a[i].l, d = a[i].d, r = a[i].r;
			int area = (d - u + 1) * (r - l + 1);
			ans[1] += val(u, d, l, r, x);
			ans[0] += area - val(u, d, l, r, x);
		}
		int cc = get(n / x);
		int cnt1 = x * x * cc + ans[0] - ans[1];
		int cnt2 = ((n / x) * (n / x) - cc) * x * x + ans[1] - ans[0];
		return min(cnt1, cnt2);
	}
	int solve() {
		int kk = sqrt(n) + 1, ans = INF;
		rep(i, 1, kk) {
			if(n % i) continue;
			if(i != n) ans = min(ans, cal(i));
			if(n / i != n)ans = min(ans, cal(n / i));
		}
		return ans;
	}

} ac;
int cal1(int u, int d, int l, int r, int v) {
	int ans = 0;
	rep(i, u, d) rep(j, l, r) {
		ans += bool((ceil(i, v) & 1) == (ceil(j, v) & 1));
	}
	return ans;
}
signed main() {
	ios::sync_with_stdio(false), cin.tie(0);
	int n, k; cin >> n >> k;
	ac.init_(n, k);
	rep(i, 1, k) {
		cin >> ac.a[i].u >> ac.a[i].l;
		cin >> ac.a[i].d >> ac.a[i].r;
	}
	cout << ac.solve() << "\n";
	return 0;
}

Compilation message

chessboard.cpp:4: warning: ignoring #pragma loop  [-Wunknown-pragmas]
    4 | #pragma loop-opt(on)
      | 
chessboard.cpp:24:13: warning: use of 'auto' in parameter declaration only available with '-fconcepts'
   24 | void vprint(auto L, auto R) {
      |             ^~~~
chessboard.cpp:24:21: warning: use of 'auto' in parameter declaration only available with '-fconcepts'
   24 | void vprint(auto L, auto R) {
      |                     ^~~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
6 Correct 1 ms 364 KB Output is correct
7 Correct 1 ms 364 KB Output is correct
8 Correct 1 ms 364 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 27 ms 3820 KB Output is correct
2 Correct 8 ms 1260 KB Output is correct
3 Correct 17 ms 2540 KB Output is correct
4 Correct 19 ms 2668 KB Output is correct
5 Correct 24 ms 3308 KB Output is correct
6 Correct 15 ms 2284 KB Output is correct
7 Correct 4 ms 748 KB Output is correct
8 Correct 15 ms 2284 KB Output is correct
9 Correct 38 ms 5248 KB Output is correct
10 Correct 22 ms 3072 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
6 Correct 1 ms 364 KB Output is correct
7 Correct 1 ms 364 KB Output is correct
8 Correct 1 ms 364 KB Output is correct
9 Correct 1 ms 512 KB Output is correct
10 Correct 1 ms 364 KB Output is correct
11 Correct 1 ms 364 KB Output is correct
12 Correct 1 ms 364 KB Output is correct
13 Correct 1 ms 364 KB Output is correct
14 Correct 1 ms 364 KB Output is correct
15 Correct 1 ms 364 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
6 Correct 1 ms 364 KB Output is correct
7 Correct 1 ms 364 KB Output is correct
8 Correct 1 ms 364 KB Output is correct
9 Correct 1 ms 512 KB Output is correct
10 Correct 1 ms 364 KB Output is correct
11 Correct 1 ms 364 KB Output is correct
12 Correct 1 ms 364 KB Output is correct
13 Correct 1 ms 364 KB Output is correct
14 Correct 1 ms 364 KB Output is correct
15 Correct 1 ms 364 KB Output is correct
16 Correct 13 ms 1644 KB Output is correct
17 Correct 31 ms 4332 KB Output is correct
18 Correct 47 ms 5008 KB Output is correct
19 Correct 133 ms 4460 KB Output is correct
20 Correct 148 ms 4972 KB Output is correct
21 Correct 30 ms 4204 KB Output is correct
22 Correct 1 ms 364 KB Output is correct
23 Correct 27 ms 2284 KB Output is correct
24 Correct 42 ms 4588 KB Output is correct
25 Correct 6 ms 748 KB Output is correct
26 Correct 26 ms 3052 KB Output is correct
27 Correct 37 ms 3564 KB Output is correct
28 Correct 44 ms 4844 KB Output is correct
29 Correct 13 ms 1900 KB Output is correct
30 Correct 2 ms 492 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 27 ms 3820 KB Output is correct
2 Correct 8 ms 1260 KB Output is correct
3 Correct 17 ms 2540 KB Output is correct
4 Correct 19 ms 2668 KB Output is correct
5 Correct 24 ms 3308 KB Output is correct
6 Correct 15 ms 2284 KB Output is correct
7 Correct 4 ms 748 KB Output is correct
8 Correct 15 ms 2284 KB Output is correct
9 Correct 38 ms 5248 KB Output is correct
10 Correct 22 ms 3072 KB Output is correct
11 Correct 1 ms 384 KB Output is correct
12 Correct 1 ms 364 KB Output is correct
13 Correct 1 ms 364 KB Output is correct
14 Correct 1 ms 364 KB Output is correct
15 Correct 1 ms 364 KB Output is correct
16 Correct 1 ms 364 KB Output is correct
17 Correct 1 ms 364 KB Output is correct
18 Correct 1 ms 364 KB Output is correct
19 Correct 1 ms 512 KB Output is correct
20 Correct 1 ms 364 KB Output is correct
21 Correct 1 ms 364 KB Output is correct
22 Correct 1 ms 364 KB Output is correct
23 Correct 1 ms 364 KB Output is correct
24 Correct 1 ms 364 KB Output is correct
25 Correct 1 ms 364 KB Output is correct
26 Correct 13 ms 1644 KB Output is correct
27 Correct 31 ms 4332 KB Output is correct
28 Correct 47 ms 5008 KB Output is correct
29 Correct 133 ms 4460 KB Output is correct
30 Correct 148 ms 4972 KB Output is correct
31 Correct 30 ms 4204 KB Output is correct
32 Correct 1 ms 364 KB Output is correct
33 Correct 27 ms 2284 KB Output is correct
34 Correct 42 ms 4588 KB Output is correct
35 Correct 6 ms 748 KB Output is correct
36 Correct 26 ms 3052 KB Output is correct
37 Correct 37 ms 3564 KB Output is correct
38 Correct 44 ms 4844 KB Output is correct
39 Correct 13 ms 1900 KB Output is correct
40 Correct 2 ms 492 KB Output is correct
41 Correct 117 ms 4972 KB Output is correct
42 Correct 48 ms 5612 KB Output is correct
43 Correct 73 ms 5012 KB Output is correct
44 Correct 47 ms 5356 KB Output is correct
45 Correct 41 ms 5740 KB Output is correct
46 Correct 137 ms 5484 KB Output is correct
47 Correct 36 ms 5100 KB Output is correct
48 Correct 60 ms 5100 KB Output is correct
49 Correct 43 ms 4972 KB Output is correct
50 Correct 554 ms 5356 KB Output is correct
51 Correct 590 ms 5708 KB Output is correct
52 Correct 552 ms 5356 KB Output is correct
53 Correct 575 ms 5612 KB Output is correct
54 Correct 531 ms 5228 KB Output is correct
55 Correct 596 ms 5868 KB Output is correct
56 Correct 519 ms 5100 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
6 Correct 1 ms 364 KB Output is correct
7 Correct 1 ms 364 KB Output is correct
8 Correct 1 ms 364 KB Output is correct
9 Correct 27 ms 3820 KB Output is correct
10 Correct 8 ms 1260 KB Output is correct
11 Correct 17 ms 2540 KB Output is correct
12 Correct 19 ms 2668 KB Output is correct
13 Correct 24 ms 3308 KB Output is correct
14 Correct 15 ms 2284 KB Output is correct
15 Correct 4 ms 748 KB Output is correct
16 Correct 15 ms 2284 KB Output is correct
17 Correct 38 ms 5248 KB Output is correct
18 Correct 22 ms 3072 KB Output is correct
19 Correct 1 ms 384 KB Output is correct
20 Correct 1 ms 364 KB Output is correct
21 Correct 1 ms 364 KB Output is correct
22 Correct 1 ms 364 KB Output is correct
23 Correct 1 ms 364 KB Output is correct
24 Correct 1 ms 364 KB Output is correct
25 Correct 1 ms 364 KB Output is correct
26 Correct 1 ms 364 KB Output is correct
27 Correct 1 ms 512 KB Output is correct
28 Correct 1 ms 364 KB Output is correct
29 Correct 1 ms 364 KB Output is correct
30 Correct 1 ms 364 KB Output is correct
31 Correct 1 ms 364 KB Output is correct
32 Correct 1 ms 364 KB Output is correct
33 Correct 1 ms 364 KB Output is correct
34 Correct 13 ms 1644 KB Output is correct
35 Correct 31 ms 4332 KB Output is correct
36 Correct 47 ms 5008 KB Output is correct
37 Correct 133 ms 4460 KB Output is correct
38 Correct 148 ms 4972 KB Output is correct
39 Correct 30 ms 4204 KB Output is correct
40 Correct 1 ms 364 KB Output is correct
41 Correct 27 ms 2284 KB Output is correct
42 Correct 42 ms 4588 KB Output is correct
43 Correct 6 ms 748 KB Output is correct
44 Correct 26 ms 3052 KB Output is correct
45 Correct 37 ms 3564 KB Output is correct
46 Correct 44 ms 4844 KB Output is correct
47 Correct 13 ms 1900 KB Output is correct
48 Correct 2 ms 492 KB Output is correct
49 Correct 117 ms 4972 KB Output is correct
50 Correct 48 ms 5612 KB Output is correct
51 Correct 73 ms 5012 KB Output is correct
52 Correct 47 ms 5356 KB Output is correct
53 Correct 41 ms 5740 KB Output is correct
54 Correct 137 ms 5484 KB Output is correct
55 Correct 36 ms 5100 KB Output is correct
56 Correct 60 ms 5100 KB Output is correct
57 Correct 43 ms 4972 KB Output is correct
58 Correct 554 ms 5356 KB Output is correct
59 Correct 590 ms 5708 KB Output is correct
60 Correct 552 ms 5356 KB Output is correct
61 Correct 575 ms 5612 KB Output is correct
62 Correct 531 ms 5228 KB Output is correct
63 Correct 596 ms 5868 KB Output is correct
64 Correct 519 ms 5100 KB Output is correct
65 Correct 1 ms 364 KB Output is correct
66 Correct 1 ms 364 KB Output is correct
67 Correct 585 ms 5356 KB Output is correct
68 Correct 611 ms 5228 KB Output is correct
69 Correct 509 ms 4844 KB Output is correct
70 Correct 551 ms 5100 KB Output is correct
71 Correct 559 ms 5100 KB Output is correct
72 Correct 528 ms 4972 KB Output is correct
73 Correct 532 ms 4972 KB Output is correct
74 Correct 579 ms 5228 KB Output is correct
75 Correct 560 ms 4972 KB Output is correct
76 Correct 591 ms 5228 KB Output is correct
77 Correct 106 ms 5484 KB Output is correct
78 Correct 47 ms 5100 KB Output is correct
79 Correct 76 ms 4972 KB Output is correct
80 Correct 80 ms 4972 KB Output is correct
81 Correct 75 ms 4844 KB Output is correct
82 Correct 67 ms 5228 KB Output is correct
83 Correct 54 ms 4972 KB Output is correct
84 Correct 350 ms 5356 KB Output is correct
85 Correct 613 ms 5612 KB Output is correct
86 Correct 1 ms 364 KB Output is correct
87 Correct 1 ms 364 KB Output is correct
88 Correct 620 ms 5740 KB Output is correct
89 Correct 117 ms 1388 KB Output is correct
90 Correct 1 ms 364 KB Output is correct