Submission #378613

# Submission time Handle Problem Language Result Execution time Memory
378613 2021-03-17T02:17:27 Z hhhhaura Chessboard (IZhO18_chessboard) C++14
70 / 100
239 ms 3436 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];
		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;

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 0 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 24 ms 2284 KB Output is correct
2 Correct 7 ms 876 KB Output is correct
3 Correct 15 ms 1516 KB Output is correct
4 Correct 19 ms 1772 KB Output is correct
5 Correct 21 ms 2028 KB Output is correct
6 Correct 14 ms 1388 KB Output is correct
7 Correct 4 ms 620 KB Output is correct
8 Correct 14 ms 1388 KB Output is correct
9 Correct 34 ms 3180 KB Output is correct
10 Correct 24 ms 1900 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 1 ms 368 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 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 1 ms 368 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 10 ms 1132 KB Output is correct
17 Correct 27 ms 2924 KB Output is correct
18 Correct 35 ms 3436 KB Output is correct
19 Correct 63 ms 3052 KB Output is correct
20 Correct 79 ms 3436 KB Output is correct
21 Correct 26 ms 2924 KB Output is correct
22 Correct 1 ms 364 KB Output is correct
23 Correct 18 ms 1644 KB Output is correct
24 Correct 32 ms 3180 KB Output is correct
25 Correct 4 ms 620 KB Output is correct
26 Correct 20 ms 2156 KB Output is correct
27 Correct 26 ms 2412 KB Output is correct
28 Correct 34 ms 3308 KB Output is correct
29 Correct 11 ms 1388 KB Output is correct
30 Correct 1 ms 364 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 24 ms 2284 KB Output is correct
2 Correct 7 ms 876 KB Output is correct
3 Correct 15 ms 1516 KB Output is correct
4 Correct 19 ms 1772 KB Output is correct
5 Correct 21 ms 2028 KB Output is correct
6 Correct 14 ms 1388 KB Output is correct
7 Correct 4 ms 620 KB Output is correct
8 Correct 14 ms 1388 KB Output is correct
9 Correct 34 ms 3180 KB Output is correct
10 Correct 24 ms 1900 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 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 368 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 10 ms 1132 KB Output is correct
27 Correct 27 ms 2924 KB Output is correct
28 Correct 35 ms 3436 KB Output is correct
29 Correct 63 ms 3052 KB Output is correct
30 Correct 79 ms 3436 KB Output is correct
31 Correct 26 ms 2924 KB Output is correct
32 Correct 1 ms 364 KB Output is correct
33 Correct 18 ms 1644 KB Output is correct
34 Correct 32 ms 3180 KB Output is correct
35 Correct 4 ms 620 KB Output is correct
36 Correct 20 ms 2156 KB Output is correct
37 Correct 26 ms 2412 KB Output is correct
38 Correct 34 ms 3308 KB Output is correct
39 Correct 11 ms 1388 KB Output is correct
40 Correct 1 ms 364 KB Output is correct
41 Correct 60 ms 2924 KB Output is correct
42 Correct 38 ms 3308 KB Output is correct
43 Correct 46 ms 2924 KB Output is correct
44 Correct 43 ms 3328 KB Output is correct
45 Correct 37 ms 3436 KB Output is correct
46 Correct 68 ms 3180 KB Output is correct
47 Correct 36 ms 3200 KB Output is correct
48 Correct 41 ms 3052 KB Output is correct
49 Correct 34 ms 2924 KB Output is correct
50 Correct 227 ms 3180 KB Output is correct
51 Correct 233 ms 3328 KB Output is correct
52 Correct 226 ms 3180 KB Output is correct
53 Correct 231 ms 3308 KB Output is correct
54 Correct 222 ms 3180 KB Output is correct
55 Correct 239 ms 3436 KB Output is correct
56 Correct 208 ms 3052 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 0 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 24 ms 2284 KB Output is correct
10 Correct 7 ms 876 KB Output is correct
11 Correct 15 ms 1516 KB Output is correct
12 Correct 19 ms 1772 KB Output is correct
13 Correct 21 ms 2028 KB Output is correct
14 Correct 14 ms 1388 KB Output is correct
15 Correct 4 ms 620 KB Output is correct
16 Correct 14 ms 1388 KB Output is correct
17 Correct 34 ms 3180 KB Output is correct
18 Correct 24 ms 1900 KB Output is correct
19 Correct 1 ms 364 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 368 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 10 ms 1132 KB Output is correct
35 Correct 27 ms 2924 KB Output is correct
36 Correct 35 ms 3436 KB Output is correct
37 Correct 63 ms 3052 KB Output is correct
38 Correct 79 ms 3436 KB Output is correct
39 Correct 26 ms 2924 KB Output is correct
40 Correct 1 ms 364 KB Output is correct
41 Correct 18 ms 1644 KB Output is correct
42 Correct 32 ms 3180 KB Output is correct
43 Correct 4 ms 620 KB Output is correct
44 Correct 20 ms 2156 KB Output is correct
45 Correct 26 ms 2412 KB Output is correct
46 Correct 34 ms 3308 KB Output is correct
47 Correct 11 ms 1388 KB Output is correct
48 Correct 1 ms 364 KB Output is correct
49 Correct 60 ms 2924 KB Output is correct
50 Correct 38 ms 3308 KB Output is correct
51 Correct 46 ms 2924 KB Output is correct
52 Correct 43 ms 3328 KB Output is correct
53 Correct 37 ms 3436 KB Output is correct
54 Correct 68 ms 3180 KB Output is correct
55 Correct 36 ms 3200 KB Output is correct
56 Correct 41 ms 3052 KB Output is correct
57 Correct 34 ms 2924 KB Output is correct
58 Correct 227 ms 3180 KB Output is correct
59 Correct 233 ms 3328 KB Output is correct
60 Correct 226 ms 3180 KB Output is correct
61 Correct 231 ms 3308 KB Output is correct
62 Correct 222 ms 3180 KB Output is correct
63 Correct 239 ms 3436 KB Output is correct
64 Correct 208 ms 3052 KB Output is correct
65 Correct 1 ms 364 KB Output is correct
66 Incorrect 1 ms 364 KB Output isn't correct
67 Halted 0 ms 0 KB -