Submission #879840

# Submission time Handle Problem Language Result Execution time Memory
879840 2023-11-28T08:14:38 Z KiaRez Chessboard (IZhO18_chessboard) C++17
100 / 100
239 ms 6704 KB
/*
    IN THE NAME OF GOD
*/
#include <bits/stdc++.h>

// #pragma GCC target("avx2,bmi,bmi2,lzcnt,popcnt")
// #pragma GCC optimize("O3")
// #pragma GCC optimize("unroll-loops")

using namespace std;

typedef long long ll;
typedef pair<ll, ll> pll;
typedef pair<int, int> pii;
typedef long double ld;

#define F                                      first
#define S                                      second
#define Mp                                     make_pair
#define pb                                     push_back
#define pf                                     push_front
#define size(x)                                ((ll)x.size())
#define all(x)                                 (x).begin(),(x).end()
#define kill(x)		                           cout << x << '\n', exit(0);
#define fuck(x)                                cout << "(" << #x << " , " << x << ")" << endl
#define endl                                   '\n'

const int N = 1e5+23, lg = 18;
ll Mod = 1e9+7; //998244353;

inline ll MOD(ll a, ll mod=Mod) {a%=mod; (a<0)&&(a+=mod); return a;}
inline ll poww(ll a, ll b, ll mod=Mod) {
    ll ans = 1;
    a=MOD(a, mod);
    while (b) {
        if (b & 1) ans = MOD(ans*a, mod);
        b >>= 1;
        a = MOD(a*a, mod);
    }
    return ans;
}

ll n, ans=1e18, k, pref[N], x[2][N], y[2][N];
int main () {
	ios_base::sync_with_stdio(false), cin.tie(0);

	cin>>n>>k;
	for(int i=1; i<=k; i++) {
		cin>>x[0][i]>>y[0][i]>>x[1][i]>>y[1][i];
	}

	for(ll d=1; d<n; d++) {
		if(n%d != 0) continue;
		for(int i=1; i<=n; i++) {
			pref[i] = pref[i-1] + (((i-1)/d)%2==0 ? -1 : 1);
		}
		ll tmp = 0;
		for(int i=1; i<=k; i++) {
			ll sz = 0, tx = x[0][i], f = pref[y[1][i]] - pref[y[0][i]-1];
			ll wh = (((tx-1)/d)%2==0 ? 1 : -1);

			if(tx%d==0) tx++;
			else tx += (d - (tx%d) + 1);
			if(x[1][i] < tx) {
				tmp += ((x[1][i]-x[0][i]+1) * wh * f);
				continue;
			}
			tmp += ((tx - x[0][i]) * wh * f);
			tx += (((x[1][i]-tx)/(2*d))*2*d);

			if(x[1][i]-tx >= d) {
				tmp += (d * -1ll * wh * f);
				tmp += ((x[1][i]-d-tx+1) * wh * f);
			} else {
				tmp += ((x[1][i]-tx+1) * -1ll * wh * f);
			}
		}
		ll res = ((n/d)/2) * n * d;
		if((n/d)%2 == 1) {
			res += (((n/d+1)/2) * d*d);
		}
		res += tmp;
		ans = min(ans, res);
		ans = min(ans, n*n - res);
	}
	
	cout<<ans<<endl;

	return 0;
}

Compilation message

chessboard.cpp: In function 'int main()':
chessboard.cpp:59:7: warning: unused variable 'sz' [-Wunused-variable]
   59 |    ll sz = 0, tx = x[0][i], f = pref[y[1][i]] - pref[y[0][i]-1];
      |       ^~
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 344 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 16 ms 4952 KB Output is correct
2 Correct 5 ms 3164 KB Output is correct
3 Correct 11 ms 4456 KB Output is correct
4 Correct 10 ms 3932 KB Output is correct
5 Correct 14 ms 4688 KB Output is correct
6 Correct 9 ms 3928 KB Output is correct
7 Correct 3 ms 2776 KB Output is correct
8 Correct 10 ms 3928 KB Output is correct
9 Correct 31 ms 5704 KB Output is correct
10 Correct 13 ms 4440 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2392 KB Output is correct
2 Correct 1 ms 2396 KB Output is correct
3 Correct 1 ms 2396 KB Output is correct
4 Correct 1 ms 2396 KB Output is correct
5 Correct 1 ms 2396 KB Output is correct
6 Correct 1 ms 2396 KB Output is correct
7 Correct 1 ms 2396 KB Output is correct
8 Correct 1 ms 2396 KB Output is correct
9 Correct 1 ms 2396 KB Output is correct
10 Correct 1 ms 2396 KB Output is correct
11 Correct 1 ms 2392 KB Output is correct
12 Correct 1 ms 2396 KB Output is correct
13 Correct 1 ms 2396 KB Output is correct
14 Correct 1 ms 2392 KB Output is correct
15 Correct 1 ms 2392 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2392 KB Output is correct
2 Correct 1 ms 2396 KB Output is correct
3 Correct 1 ms 2396 KB Output is correct
4 Correct 1 ms 2396 KB Output is correct
5 Correct 1 ms 2396 KB Output is correct
6 Correct 1 ms 2396 KB Output is correct
7 Correct 1 ms 2396 KB Output is correct
8 Correct 1 ms 2396 KB Output is correct
9 Correct 1 ms 2396 KB Output is correct
10 Correct 1 ms 2396 KB Output is correct
11 Correct 1 ms 2392 KB Output is correct
12 Correct 1 ms 2396 KB Output is correct
13 Correct 1 ms 2396 KB Output is correct
14 Correct 1 ms 2392 KB Output is correct
15 Correct 1 ms 2392 KB Output is correct
16 Correct 7 ms 3164 KB Output is correct
17 Correct 17 ms 4548 KB Output is correct
18 Correct 22 ms 5104 KB Output is correct
19 Correct 41 ms 4832 KB Output is correct
20 Correct 53 ms 5160 KB Output is correct
21 Correct 17 ms 4624 KB Output is correct
22 Correct 1 ms 2396 KB Output is correct
23 Correct 12 ms 3676 KB Output is correct
24 Correct 21 ms 4700 KB Output is correct
25 Correct 3 ms 2652 KB Output is correct
26 Correct 13 ms 3916 KB Output is correct
27 Correct 17 ms 4184 KB Output is correct
28 Correct 22 ms 4952 KB Output is correct
29 Correct 7 ms 3420 KB Output is correct
30 Correct 1 ms 2396 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 16 ms 4952 KB Output is correct
2 Correct 5 ms 3164 KB Output is correct
3 Correct 11 ms 4456 KB Output is correct
4 Correct 10 ms 3932 KB Output is correct
5 Correct 14 ms 4688 KB Output is correct
6 Correct 9 ms 3928 KB Output is correct
7 Correct 3 ms 2776 KB Output is correct
8 Correct 10 ms 3928 KB Output is correct
9 Correct 31 ms 5704 KB Output is correct
10 Correct 13 ms 4440 KB Output is correct
11 Correct 1 ms 2392 KB Output is correct
12 Correct 1 ms 2396 KB Output is correct
13 Correct 1 ms 2396 KB Output is correct
14 Correct 1 ms 2396 KB Output is correct
15 Correct 1 ms 2396 KB Output is correct
16 Correct 1 ms 2396 KB Output is correct
17 Correct 1 ms 2396 KB Output is correct
18 Correct 1 ms 2396 KB Output is correct
19 Correct 1 ms 2396 KB Output is correct
20 Correct 1 ms 2396 KB Output is correct
21 Correct 1 ms 2392 KB Output is correct
22 Correct 1 ms 2396 KB Output is correct
23 Correct 1 ms 2396 KB Output is correct
24 Correct 1 ms 2392 KB Output is correct
25 Correct 1 ms 2392 KB Output is correct
26 Correct 7 ms 3164 KB Output is correct
27 Correct 17 ms 4548 KB Output is correct
28 Correct 22 ms 5104 KB Output is correct
29 Correct 41 ms 4832 KB Output is correct
30 Correct 53 ms 5160 KB Output is correct
31 Correct 17 ms 4624 KB Output is correct
32 Correct 1 ms 2396 KB Output is correct
33 Correct 12 ms 3676 KB Output is correct
34 Correct 21 ms 4700 KB Output is correct
35 Correct 3 ms 2652 KB Output is correct
36 Correct 13 ms 3916 KB Output is correct
37 Correct 17 ms 4184 KB Output is correct
38 Correct 22 ms 4952 KB Output is correct
39 Correct 7 ms 3420 KB Output is correct
40 Correct 1 ms 2396 KB Output is correct
41 Correct 53 ms 5980 KB Output is correct
42 Correct 27 ms 6480 KB Output is correct
43 Correct 37 ms 5968 KB Output is correct
44 Correct 30 ms 6316 KB Output is correct
45 Correct 27 ms 6536 KB Output is correct
46 Correct 57 ms 6236 KB Output is correct
47 Correct 22 ms 5972 KB Output is correct
48 Correct 32 ms 6112 KB Output is correct
49 Correct 25 ms 6104 KB Output is correct
50 Correct 200 ms 6480 KB Output is correct
51 Correct 211 ms 6496 KB Output is correct
52 Correct 203 ms 6224 KB Output is correct
53 Correct 208 ms 6476 KB Output is correct
54 Correct 207 ms 6228 KB Output is correct
55 Correct 214 ms 6492 KB Output is correct
56 Correct 193 ms 6076 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 344 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 16 ms 4952 KB Output is correct
10 Correct 5 ms 3164 KB Output is correct
11 Correct 11 ms 4456 KB Output is correct
12 Correct 10 ms 3932 KB Output is correct
13 Correct 14 ms 4688 KB Output is correct
14 Correct 9 ms 3928 KB Output is correct
15 Correct 3 ms 2776 KB Output is correct
16 Correct 10 ms 3928 KB Output is correct
17 Correct 31 ms 5704 KB Output is correct
18 Correct 13 ms 4440 KB Output is correct
19 Correct 1 ms 2392 KB Output is correct
20 Correct 1 ms 2396 KB Output is correct
21 Correct 1 ms 2396 KB Output is correct
22 Correct 1 ms 2396 KB Output is correct
23 Correct 1 ms 2396 KB Output is correct
24 Correct 1 ms 2396 KB Output is correct
25 Correct 1 ms 2396 KB Output is correct
26 Correct 1 ms 2396 KB Output is correct
27 Correct 1 ms 2396 KB Output is correct
28 Correct 1 ms 2396 KB Output is correct
29 Correct 1 ms 2392 KB Output is correct
30 Correct 1 ms 2396 KB Output is correct
31 Correct 1 ms 2396 KB Output is correct
32 Correct 1 ms 2392 KB Output is correct
33 Correct 1 ms 2392 KB Output is correct
34 Correct 7 ms 3164 KB Output is correct
35 Correct 17 ms 4548 KB Output is correct
36 Correct 22 ms 5104 KB Output is correct
37 Correct 41 ms 4832 KB Output is correct
38 Correct 53 ms 5160 KB Output is correct
39 Correct 17 ms 4624 KB Output is correct
40 Correct 1 ms 2396 KB Output is correct
41 Correct 12 ms 3676 KB Output is correct
42 Correct 21 ms 4700 KB Output is correct
43 Correct 3 ms 2652 KB Output is correct
44 Correct 13 ms 3916 KB Output is correct
45 Correct 17 ms 4184 KB Output is correct
46 Correct 22 ms 4952 KB Output is correct
47 Correct 7 ms 3420 KB Output is correct
48 Correct 1 ms 2396 KB Output is correct
49 Correct 53 ms 5980 KB Output is correct
50 Correct 27 ms 6480 KB Output is correct
51 Correct 37 ms 5968 KB Output is correct
52 Correct 30 ms 6316 KB Output is correct
53 Correct 27 ms 6536 KB Output is correct
54 Correct 57 ms 6236 KB Output is correct
55 Correct 22 ms 5972 KB Output is correct
56 Correct 32 ms 6112 KB Output is correct
57 Correct 25 ms 6104 KB Output is correct
58 Correct 200 ms 6480 KB Output is correct
59 Correct 211 ms 6496 KB Output is correct
60 Correct 203 ms 6224 KB Output is correct
61 Correct 208 ms 6476 KB Output is correct
62 Correct 207 ms 6228 KB Output is correct
63 Correct 214 ms 6492 KB Output is correct
64 Correct 193 ms 6076 KB Output is correct
65 Correct 1 ms 2396 KB Output is correct
66 Correct 1 ms 2548 KB Output is correct
67 Correct 222 ms 6188 KB Output is correct
68 Correct 223 ms 6280 KB Output is correct
69 Correct 201 ms 5920 KB Output is correct
70 Correct 215 ms 6236 KB Output is correct
71 Correct 213 ms 5972 KB Output is correct
72 Correct 211 ms 6328 KB Output is correct
73 Correct 208 ms 6228 KB Output is correct
74 Correct 219 ms 6296 KB Output is correct
75 Correct 213 ms 6152 KB Output is correct
76 Correct 226 ms 6280 KB Output is correct
77 Correct 51 ms 6704 KB Output is correct
78 Correct 35 ms 6140 KB Output is correct
79 Correct 39 ms 5980 KB Output is correct
80 Correct 40 ms 6224 KB Output is correct
81 Correct 38 ms 5972 KB Output is correct
82 Correct 35 ms 6264 KB Output is correct
83 Correct 30 ms 5972 KB Output is correct
84 Correct 144 ms 6612 KB Output is correct
85 Correct 223 ms 6520 KB Output is correct
86 Correct 57 ms 3164 KB Output is correct
87 Correct 57 ms 3164 KB Output is correct
88 Correct 239 ms 6612 KB Output is correct
89 Correct 91 ms 3676 KB Output is correct
90 Correct 57 ms 3164 KB Output is correct