Submission #670074

# Submission time Handle Problem Language Result Execution time Memory
670074 2022-12-08T02:57:37 Z Kaztaev_Alisher Chessboard (IZhO18_chessboard) C++17
100 / 100
316 ms 5836 KB
//#pragma GCC optomize ("Ofast")
//#pragma GCC optomize ("unroll-loops")
//#pragma GCC target ("avx,avx2,fma")

#include <bits/stdc++.h>
#define F first
#define S second
#define pb push_back
#define sz size
#define cl clear
#define ins insert
#define ers erase
#define pii pair < int , int >
#define pll pair< long long  , long long >
#define all(x) x.begin() , x.end()
#define ios ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define file(s) if (fopen(s".in", "r")) freopen(s".in", "r", stdin), freopen(s".out", "w", stdout)
#define tostr(x) to_string(x)
#define tonum(s) atoi(s.c_str())
#define seon(x) setprecision(x)
#define bpop(x) __builtin_popcount(x)
#define deb(x) cerr << #x  << " = " << x << endl;
#define int ll

typedef long long ll;
typedef unsigned long long ull;
typedef double db;
typedef long double ldb;
const double PI = 3.14159265;

const ll N = 1e5+5;
const ll mod = 1e9+7;
const ll inf = 1e9;
const ll INF = 1e18;

using namespace std;

struct {
	int x1,y1,x2,y2;
}t[N];

pair<int,int> get(int l,  int r , int len) {
	l --;
	r --;
	int sz = r-l+1;
	int ev = 0;
	int nxl = l/len*len+len;
	if(l/len%2 == 0) ev += min(r+1, nxl) - l;
	l = nxl;
	if(l > r) return {ev, sz-ev};
	
	int pdr = r/len*len-1;
	if(r/len%2 == 0) {
		ev += r-max(pdr,l-1);
	}
	r = pdr;
	if(l > r) return {ev, sz-ev};
	
	if(l/len%2 != r/len%2) {
		ev += (r-l+1)/2;
	}
	else {
		ev += ((r-l+1)/len+(l/len%2==0))/2*len;
	}
	return {ev, sz-ev};
}

void solve(){
	int n , k;
	cin>> n >> k;
	for(int i = 1; i <= k; i ++) {
		cin >> t[i].x1 >> t[i].y1 >> t[i].x2 >> t[i].y2;
	}
	vector<int> dels;
	for(int i = 1; i*i <= n; i++) {
		if(n%i == 0) {
			dels.push_back(i);
			if(n/i != i && i > 1) dels.push_back(n/i);
		}
	}
	sort(all(dels));
	int ans = INF;
	for(auto len : dels) {
		int m = n/len;
		int ob = (m*m-(m*m/2))*len*len;
		int rb = 0;
		int ww = 0;
		for(int i = 1; i <= k; i ++) {
			pair<int,int> X = get(t[i].x1, t[i].x2, len);
			pair<int,int> Y = get(t[i].y1, t[i].y2, len);
			rb += X.F * Y.F;
			rb += X.S * Y.S;
			ww += X.F * Y.S;
			ww += X.S * Y.F;
		}
		ans = min(ans, ww + (ob-rb));
		ans = min(ans, rb + (n*n-ob-ww));
	}
	cout << ans;
}
signed main(){
	ios;
	int t = 1;
//	cin >> t;
	while(t--) solve();
	return 0;
}
/*
*/
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 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 0 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 23 ms 2184 KB Output is correct
2 Correct 6 ms 1108 KB Output is correct
3 Correct 13 ms 2356 KB Output is correct
4 Correct 16 ms 2772 KB Output is correct
5 Correct 18 ms 3276 KB Output is correct
6 Correct 11 ms 2208 KB Output is correct
7 Correct 3 ms 724 KB Output is correct
8 Correct 11 ms 2232 KB Output is correct
9 Correct 28 ms 5200 KB Output is correct
10 Correct 17 ms 3008 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 0 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 0 ms 340 KB Output is correct
10 Correct 0 ms 212 KB Output is correct
11 Correct 1 ms 340 KB Output is correct
12 Correct 1 ms 340 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
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 0 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 0 ms 340 KB Output is correct
10 Correct 0 ms 212 KB Output is correct
11 Correct 1 ms 340 KB Output is correct
12 Correct 1 ms 340 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 8 ms 1108 KB Output is correct
17 Correct 21 ms 2844 KB Output is correct
18 Correct 28 ms 3344 KB Output is correct
19 Correct 63 ms 3140 KB Output is correct
20 Correct 70 ms 3328 KB Output is correct
21 Correct 21 ms 2772 KB Output is correct
22 Correct 0 ms 340 KB Output is correct
23 Correct 15 ms 1748 KB Output is correct
24 Correct 32 ms 3148 KB Output is correct
25 Correct 3 ms 468 KB Output is correct
26 Correct 19 ms 2020 KB Output is correct
27 Correct 22 ms 2356 KB Output is correct
28 Correct 26 ms 3216 KB Output is correct
29 Correct 8 ms 1364 KB Output is correct
30 Correct 1 ms 340 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 23 ms 2184 KB Output is correct
2 Correct 6 ms 1108 KB Output is correct
3 Correct 13 ms 2356 KB Output is correct
4 Correct 16 ms 2772 KB Output is correct
5 Correct 18 ms 3276 KB Output is correct
6 Correct 11 ms 2208 KB Output is correct
7 Correct 3 ms 724 KB Output is correct
8 Correct 11 ms 2232 KB Output is correct
9 Correct 28 ms 5200 KB Output is correct
10 Correct 17 ms 3008 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 212 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
15 Correct 1 ms 340 KB Output is correct
16 Correct 0 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 0 ms 340 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 8 ms 1108 KB Output is correct
27 Correct 21 ms 2844 KB Output is correct
28 Correct 28 ms 3344 KB Output is correct
29 Correct 63 ms 3140 KB Output is correct
30 Correct 70 ms 3328 KB Output is correct
31 Correct 21 ms 2772 KB Output is correct
32 Correct 0 ms 340 KB Output is correct
33 Correct 15 ms 1748 KB Output is correct
34 Correct 32 ms 3148 KB Output is correct
35 Correct 3 ms 468 KB Output is correct
36 Correct 19 ms 2020 KB Output is correct
37 Correct 22 ms 2356 KB Output is correct
38 Correct 26 ms 3216 KB Output is correct
39 Correct 8 ms 1364 KB Output is correct
40 Correct 1 ms 340 KB Output is correct
41 Correct 64 ms 4912 KB Output is correct
42 Correct 34 ms 5500 KB Output is correct
43 Correct 41 ms 4892 KB Output is correct
44 Correct 35 ms 5256 KB Output is correct
45 Correct 34 ms 5696 KB Output is correct
46 Correct 69 ms 5432 KB Output is correct
47 Correct 26 ms 4960 KB Output is correct
48 Correct 36 ms 5068 KB Output is correct
49 Correct 31 ms 4820 KB Output is correct
50 Correct 241 ms 5316 KB Output is correct
51 Correct 257 ms 5644 KB Output is correct
52 Correct 241 ms 5280 KB Output is correct
53 Correct 257 ms 5624 KB Output is correct
54 Correct 237 ms 5124 KB Output is correct
55 Correct 264 ms 5820 KB Output is correct
56 Correct 229 ms 5016 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 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 0 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 23 ms 2184 KB Output is correct
10 Correct 6 ms 1108 KB Output is correct
11 Correct 13 ms 2356 KB Output is correct
12 Correct 16 ms 2772 KB Output is correct
13 Correct 18 ms 3276 KB Output is correct
14 Correct 11 ms 2208 KB Output is correct
15 Correct 3 ms 724 KB Output is correct
16 Correct 11 ms 2232 KB Output is correct
17 Correct 28 ms 5200 KB Output is correct
18 Correct 17 ms 3008 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 212 KB Output is correct
22 Correct 1 ms 340 KB Output is correct
23 Correct 1 ms 340 KB Output is correct
24 Correct 0 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 0 ms 340 KB Output is correct
28 Correct 0 ms 212 KB Output is correct
29 Correct 1 ms 340 KB Output is correct
30 Correct 1 ms 340 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 8 ms 1108 KB Output is correct
35 Correct 21 ms 2844 KB Output is correct
36 Correct 28 ms 3344 KB Output is correct
37 Correct 63 ms 3140 KB Output is correct
38 Correct 70 ms 3328 KB Output is correct
39 Correct 21 ms 2772 KB Output is correct
40 Correct 0 ms 340 KB Output is correct
41 Correct 15 ms 1748 KB Output is correct
42 Correct 32 ms 3148 KB Output is correct
43 Correct 3 ms 468 KB Output is correct
44 Correct 19 ms 2020 KB Output is correct
45 Correct 22 ms 2356 KB Output is correct
46 Correct 26 ms 3216 KB Output is correct
47 Correct 8 ms 1364 KB Output is correct
48 Correct 1 ms 340 KB Output is correct
49 Correct 64 ms 4912 KB Output is correct
50 Correct 34 ms 5500 KB Output is correct
51 Correct 41 ms 4892 KB Output is correct
52 Correct 35 ms 5256 KB Output is correct
53 Correct 34 ms 5696 KB Output is correct
54 Correct 69 ms 5432 KB Output is correct
55 Correct 26 ms 4960 KB Output is correct
56 Correct 36 ms 5068 KB Output is correct
57 Correct 31 ms 4820 KB Output is correct
58 Correct 241 ms 5316 KB Output is correct
59 Correct 257 ms 5644 KB Output is correct
60 Correct 241 ms 5280 KB Output is correct
61 Correct 257 ms 5624 KB Output is correct
62 Correct 237 ms 5124 KB Output is correct
63 Correct 264 ms 5820 KB Output is correct
64 Correct 229 ms 5016 KB Output is correct
65 Correct 0 ms 212 KB Output is correct
66 Correct 0 ms 212 KB Output is correct
67 Correct 307 ms 5460 KB Output is correct
68 Correct 300 ms 5580 KB Output is correct
69 Correct 258 ms 4828 KB Output is correct
70 Correct 272 ms 5292 KB Output is correct
71 Correct 279 ms 5124 KB Output is correct
72 Correct 266 ms 5136 KB Output is correct
73 Correct 277 ms 5120 KB Output is correct
74 Correct 299 ms 5408 KB Output is correct
75 Correct 286 ms 5176 KB Output is correct
76 Correct 299 ms 5504 KB Output is correct
77 Correct 68 ms 5772 KB Output is correct
78 Correct 34 ms 5112 KB Output is correct
79 Correct 52 ms 4976 KB Output is correct
80 Correct 52 ms 5236 KB Output is correct
81 Correct 49 ms 4812 KB Output is correct
82 Correct 45 ms 5460 KB Output is correct
83 Correct 40 ms 5020 KB Output is correct
84 Correct 188 ms 5640 KB Output is correct
85 Correct 316 ms 5732 KB Output is correct
86 Correct 1 ms 212 KB Output is correct
87 Correct 1 ms 212 KB Output is correct
88 Correct 316 ms 5836 KB Output is correct
89 Correct 66 ms 1340 KB Output is correct
90 Correct 0 ms 328 KB Output is correct