Submission #492397

# Submission time Handle Problem Language Result Execution time Memory
492397 2021-12-07T04:56:33 Z hohohaha Chessboard (IZhO18_chessboard) C++14
100 / 100
322 ms 4576 KB
// #pragma GCC optimize("Ofast")
// #pragma GCC targt("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,avx2,fma")
// #pragma GCC optimize("unroll-loops")

#include "bits/stdc++.h"

// #include <ext/pb_ds/assoc_container.hpp>
// #include <ext/pb_ds/trie_policy.hpp>
// #include <ext/rope>

using namespace std;
// using namespace __gnu_pbds;
// using namespace __gnu_cxx;

#define li long long
#define ld long double
#define ii pair<int, int>
#define vi vector<int> 
#define vvi vector<vi>


#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define pf push_front
#define eb emplace_back
#define em emplace
#define ob pop_back
#define om pop
#define of pop_front

#define fr front
#define bc back

#define fori(i, a, b) for(int i = (int) (a); i <= (int) (b); ++i)
#define ford(i, a, b) for(int i = (int) (a); i >= (int) (b); --i)

#define all(x) begin(x), end(x)
#define sz(x) ((int)(x).size())
#define bitc __builtin_popcountll

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
#define rand rng
#define endl '\n'
#define sp ' '

#define fastio() ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);

void solve();

signed main() {
// freopen("output.out","w",stdout);
   fastio();
   
   int tc = 1;
   
//   cin >> tc; 
   
   fori(test, 1, tc) {
      solve();
   }
   return 0;
}

const ld pi = 4 * atan(1.0), eps = 1e-9;

#define int long long
const int maxn = 200000 + 5, mod = 924844033; 

const int inf = LLONG_MAX / 2; 

int n, m; 

int sum = 0; 

vector<pair<ii, ii> > al; 

int get(int i, int k) { 
//	cout << i << sp << min(i % (2 * k), k)<< sp << (i / (2 * k) * k) << endl;
	return min(i % (2 * k), k) + (i / (2 * k) * k); 
}

void solve() {
	cin >> n>> m; 
	fori(i,1 , m) {
		int a, b, c, d; 
		cin >> a >> b >> c >> d;
		al.eb(ii(a, b), ii(c, d)); 
	}
	int ans= inf; 
	fori(i, 1, n - 1) { 
		if(n % i == 0) {
			int blocks = n * n / (i * i); int black = (blocks + 1) / 2 * i * i;
//			cout << blocks << endl;
			int a1 = black, a2 = n * n - black; 
//			cout<< "a: " << a1 << sp << a2 << endl;
			for(auto t : al) {
				int a = t.fi.fi, b = t.fi.se, c = t.se.fi, d = t.se.se; 	
				
				int area = (c - a + 1) * (d- b + 1);
				
				int h = get(c, i) - get(a - 1, i), w = get(d, i) - get(b- 1, i); 
			 	
			 	int smblack = h * w + (c - a + 1 - h) * (d - b + 1 - w); 
			 	
//			 	cout << i << sp << h << sp << w << sp << smblack << endl;;
			 	
			 	a1 -= smblack; 
			 	a2 -= area - smblack;
				
				a1 += area - smblack; 
				a2 += smblack; 
//				cout << a1 << sp << a2 << ":::" << endl;
			}
			ans = min(ans, a1); 
			ans = min(ans, a2);
		}
	}
	cout << ans; 
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
3 Correct 0 ms 204 KB Output is correct
4 Correct 0 ms 204 KB Output is correct
5 Correct 0 ms 204 KB Output is correct
6 Correct 0 ms 204 KB Output is correct
7 Correct 0 ms 204 KB Output is correct
8 Correct 0 ms 204 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 29 ms 2504 KB Output is correct
2 Correct 6 ms 1484 KB Output is correct
3 Correct 16 ms 2504 KB Output is correct
4 Correct 16 ms 2504 KB Output is correct
5 Correct 21 ms 2504 KB Output is correct
6 Correct 13 ms 2404 KB Output is correct
7 Correct 3 ms 844 KB Output is correct
8 Correct 14 ms 2504 KB Output is correct
9 Correct 35 ms 4516 KB Output is correct
10 Correct 17 ms 2504 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 332 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
4 Correct 1 ms 332 KB Output is correct
5 Correct 0 ms 332 KB Output is correct
6 Correct 1 ms 332 KB Output is correct
7 Correct 1 ms 332 KB Output is correct
8 Correct 0 ms 332 KB Output is correct
9 Correct 1 ms 332 KB Output is correct
10 Correct 0 ms 204 KB Output is correct
11 Correct 1 ms 332 KB Output is correct
12 Correct 1 ms 332 KB Output is correct
13 Correct 1 ms 332 KB Output is correct
14 Correct 1 ms 332 KB Output is correct
15 Correct 1 ms 332 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 332 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
4 Correct 1 ms 332 KB Output is correct
5 Correct 0 ms 332 KB Output is correct
6 Correct 1 ms 332 KB Output is correct
7 Correct 1 ms 332 KB Output is correct
8 Correct 0 ms 332 KB Output is correct
9 Correct 1 ms 332 KB Output is correct
10 Correct 0 ms 204 KB Output is correct
11 Correct 1 ms 332 KB Output is correct
12 Correct 1 ms 332 KB Output is correct
13 Correct 1 ms 332 KB Output is correct
14 Correct 1 ms 332 KB Output is correct
15 Correct 1 ms 332 KB Output is correct
16 Correct 9 ms 1484 KB Output is correct
17 Correct 23 ms 4548 KB Output is correct
18 Correct 35 ms 4488 KB Output is correct
19 Correct 81 ms 4540 KB Output is correct
20 Correct 94 ms 4520 KB Output is correct
21 Correct 25 ms 4488 KB Output is correct
22 Correct 1 ms 332 KB Output is correct
23 Correct 18 ms 2504 KB Output is correct
24 Correct 29 ms 4572 KB Output is correct
25 Correct 5 ms 976 KB Output is correct
26 Correct 20 ms 2452 KB Output is correct
27 Correct 27 ms 4568 KB Output is correct
28 Correct 32 ms 4492 KB Output is correct
29 Correct 12 ms 2504 KB Output is correct
30 Correct 2 ms 460 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 29 ms 2504 KB Output is correct
2 Correct 6 ms 1484 KB Output is correct
3 Correct 16 ms 2504 KB Output is correct
4 Correct 16 ms 2504 KB Output is correct
5 Correct 21 ms 2504 KB Output is correct
6 Correct 13 ms 2404 KB Output is correct
7 Correct 3 ms 844 KB Output is correct
8 Correct 14 ms 2504 KB Output is correct
9 Correct 35 ms 4516 KB Output is correct
10 Correct 17 ms 2504 KB Output is correct
11 Correct 1 ms 332 KB Output is correct
12 Correct 0 ms 204 KB Output is correct
13 Correct 1 ms 332 KB Output is correct
14 Correct 1 ms 332 KB Output is correct
15 Correct 0 ms 332 KB Output is correct
16 Correct 1 ms 332 KB Output is correct
17 Correct 1 ms 332 KB Output is correct
18 Correct 0 ms 332 KB Output is correct
19 Correct 1 ms 332 KB Output is correct
20 Correct 0 ms 204 KB Output is correct
21 Correct 1 ms 332 KB Output is correct
22 Correct 1 ms 332 KB Output is correct
23 Correct 1 ms 332 KB Output is correct
24 Correct 1 ms 332 KB Output is correct
25 Correct 1 ms 332 KB Output is correct
26 Correct 9 ms 1484 KB Output is correct
27 Correct 23 ms 4548 KB Output is correct
28 Correct 35 ms 4488 KB Output is correct
29 Correct 81 ms 4540 KB Output is correct
30 Correct 94 ms 4520 KB Output is correct
31 Correct 25 ms 4488 KB Output is correct
32 Correct 1 ms 332 KB Output is correct
33 Correct 18 ms 2504 KB Output is correct
34 Correct 29 ms 4572 KB Output is correct
35 Correct 5 ms 976 KB Output is correct
36 Correct 20 ms 2452 KB Output is correct
37 Correct 27 ms 4568 KB Output is correct
38 Correct 32 ms 4492 KB Output is correct
39 Correct 12 ms 2504 KB Output is correct
40 Correct 2 ms 460 KB Output is correct
41 Correct 91 ms 4536 KB Output is correct
42 Correct 36 ms 4532 KB Output is correct
43 Correct 47 ms 4540 KB Output is correct
44 Correct 39 ms 4544 KB Output is correct
45 Correct 34 ms 4548 KB Output is correct
46 Correct 80 ms 4548 KB Output is correct
47 Correct 27 ms 4564 KB Output is correct
48 Correct 45 ms 4492 KB Output is correct
49 Correct 35 ms 4488 KB Output is correct
50 Correct 290 ms 4560 KB Output is correct
51 Correct 304 ms 4460 KB Output is correct
52 Correct 312 ms 4540 KB Output is correct
53 Correct 310 ms 4472 KB Output is correct
54 Correct 296 ms 4548 KB Output is correct
55 Correct 322 ms 4548 KB Output is correct
56 Correct 285 ms 4540 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
3 Correct 0 ms 204 KB Output is correct
4 Correct 0 ms 204 KB Output is correct
5 Correct 0 ms 204 KB Output is correct
6 Correct 0 ms 204 KB Output is correct
7 Correct 0 ms 204 KB Output is correct
8 Correct 0 ms 204 KB Output is correct
9 Correct 29 ms 2504 KB Output is correct
10 Correct 6 ms 1484 KB Output is correct
11 Correct 16 ms 2504 KB Output is correct
12 Correct 16 ms 2504 KB Output is correct
13 Correct 21 ms 2504 KB Output is correct
14 Correct 13 ms 2404 KB Output is correct
15 Correct 3 ms 844 KB Output is correct
16 Correct 14 ms 2504 KB Output is correct
17 Correct 35 ms 4516 KB Output is correct
18 Correct 17 ms 2504 KB Output is correct
19 Correct 1 ms 332 KB Output is correct
20 Correct 0 ms 204 KB Output is correct
21 Correct 1 ms 332 KB Output is correct
22 Correct 1 ms 332 KB Output is correct
23 Correct 0 ms 332 KB Output is correct
24 Correct 1 ms 332 KB Output is correct
25 Correct 1 ms 332 KB Output is correct
26 Correct 0 ms 332 KB Output is correct
27 Correct 1 ms 332 KB Output is correct
28 Correct 0 ms 204 KB Output is correct
29 Correct 1 ms 332 KB Output is correct
30 Correct 1 ms 332 KB Output is correct
31 Correct 1 ms 332 KB Output is correct
32 Correct 1 ms 332 KB Output is correct
33 Correct 1 ms 332 KB Output is correct
34 Correct 9 ms 1484 KB Output is correct
35 Correct 23 ms 4548 KB Output is correct
36 Correct 35 ms 4488 KB Output is correct
37 Correct 81 ms 4540 KB Output is correct
38 Correct 94 ms 4520 KB Output is correct
39 Correct 25 ms 4488 KB Output is correct
40 Correct 1 ms 332 KB Output is correct
41 Correct 18 ms 2504 KB Output is correct
42 Correct 29 ms 4572 KB Output is correct
43 Correct 5 ms 976 KB Output is correct
44 Correct 20 ms 2452 KB Output is correct
45 Correct 27 ms 4568 KB Output is correct
46 Correct 32 ms 4492 KB Output is correct
47 Correct 12 ms 2504 KB Output is correct
48 Correct 2 ms 460 KB Output is correct
49 Correct 91 ms 4536 KB Output is correct
50 Correct 36 ms 4532 KB Output is correct
51 Correct 47 ms 4540 KB Output is correct
52 Correct 39 ms 4544 KB Output is correct
53 Correct 34 ms 4548 KB Output is correct
54 Correct 80 ms 4548 KB Output is correct
55 Correct 27 ms 4564 KB Output is correct
56 Correct 45 ms 4492 KB Output is correct
57 Correct 35 ms 4488 KB Output is correct
58 Correct 290 ms 4560 KB Output is correct
59 Correct 304 ms 4460 KB Output is correct
60 Correct 312 ms 4540 KB Output is correct
61 Correct 310 ms 4472 KB Output is correct
62 Correct 296 ms 4548 KB Output is correct
63 Correct 322 ms 4548 KB Output is correct
64 Correct 285 ms 4540 KB Output is correct
65 Correct 0 ms 204 KB Output is correct
66 Correct 0 ms 204 KB Output is correct
67 Correct 317 ms 4560 KB Output is correct
68 Correct 295 ms 4436 KB Output is correct
69 Correct 285 ms 4548 KB Output is correct
70 Correct 290 ms 4476 KB Output is correct
71 Correct 299 ms 4548 KB Output is correct
72 Correct 291 ms 4508 KB Output is correct
73 Correct 272 ms 4548 KB Output is correct
74 Correct 318 ms 4496 KB Output is correct
75 Correct 277 ms 4548 KB Output is correct
76 Correct 317 ms 4488 KB Output is correct
77 Correct 67 ms 4548 KB Output is correct
78 Correct 35 ms 4504 KB Output is correct
79 Correct 47 ms 4540 KB Output is correct
80 Correct 49 ms 4516 KB Output is correct
81 Correct 45 ms 4568 KB Output is correct
82 Correct 55 ms 4576 KB Output is correct
83 Correct 41 ms 4524 KB Output is correct
84 Correct 188 ms 4476 KB Output is correct
85 Correct 312 ms 4548 KB Output is correct
86 Correct 1 ms 204 KB Output is correct
87 Correct 1 ms 292 KB Output is correct
88 Correct 322 ms 4548 KB Output is correct
89 Correct 63 ms 1444 KB Output is correct
90 Correct 1 ms 204 KB Output is correct