답안 #521863

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
521863 2022-02-03T10:24:36 Z vonatlus Chessboard (IZhO18_chessboard) C++17
100 / 100
1184 ms 2724 KB
/// adil sultanov | vonat1us 

#pragma GCC optimize("O3")
//#pragma comment(linker, "/STACK:36777216")

#include<bits/stdc++.h>

#define x first
#define y second
#define pb push_back
#define sz(x) (int) x.size()
#define all(z) (z).begin(), (z).end()
 
using namespace std;

using ll = long long;
using pii = pair<int, int>;                                   

const int MOD = 1e9 + 7; 
const int INF = 1e9 + 1e2;
  
void fin() {
#ifdef AM
    freopen(".in", "r", stdin);
#endif        
}                   

const bool flag = 0;

const int N = 1e5+10;

void ma1n() {
    ll n, k;
    cin >> n >> k;
    vector<ll> v;
    for (ll i = 1; i <= sqrt(n); ++i) {
        if (n%i == 0) {
            v.pb(i);
            if (i*i != n) {
                v.pb(n/i);
            }
        }
    }
    sort(all(v));
    v.pop_back();
    vector<ll> res1(sz(v)), res2(sz(v));
    for (ll i = 0; i < sz(v); ++i) {
        ll d = v[i];
        ll cnt = n/d;
        ll cnt1 = cnt/2;
        ll cnt2 = (cnt+1)/2;
        res1[i] = cnt1*cnt2*d*d*2;
        res2[i] = n*n - res1[i];
    }
    
    auto get = [&](ll x, ll y, ll d) {
        if (x < 0 || y < 0) return 0ll;
        bool color = ((x/d)%2 != (y/d)%2); 
        ll cx = (x+1)%d;
        if (cx == 0) cx = d;
        ll cy = (y+1)%d;
        if (cy == 0) cy = d;
        ll res = 0;
        ll cur = (x/d)/2*d*cy;
        if (!color && (x/d)&1) {
            cur += d*cy;
        } 
        res += cur;
        if (color) { // black
            res += cx*cy;
        } 
        cur = (y/d)/2*d*cx;
        if (!color && (y/d)&1) {
            cur += d*cx;
        }
        res += cur;
        x = (x/d-1)*d+d-1;
        y = (y/d-1)*d+d-1;
        res += ((((x+1)/d)*((y+1)/d))/2)*d*d; 
        return res;
    };

    //cout << get(2, 2, 1) << " " << get(2, 1, 1) << " " << get(1, 2, 1) << " " << get(1, 1, 1) << "\n";
   // cout << get(2, 3, 2) << " " << get(2, 2, 2) << " " << get(1, 3, 2) << " " << get(1, 2, 2) << "\n";
    //return;

    while (k--) {
        ll a, b, c, d;
        cin >> a >> b >> c >> d;
        a--, b--, c--, d--;    
        for (ll t = 0; t < sz(v); ++t) {
            ll dv = v[t];
            ll sum = get(c, d, dv) - get(c, b-1, dv) - get(a-1, d, dv) + get(a-1, b-1, dv);
            ll inv = (c-a+1)*1ll*(d-b+1) - sum;
            //cout << "D: " << dv << ", " << a << " " << b << " " << c << " " << d << " | " << sum << " " << inv << "\n";
            res1[t] -= sum;
            res1[t] += inv;
            res2[t] -= inv;
            res2[t] += sum;
        }
    }
    ll ans = n*n;
    for (ll i = 0; i < sz(v); ++i) {
        ans = min({ans, res1[i], res2[i]});    
    }
    cout << ans;
} 

int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(nullptr), fin();
    int ts = 1;
    if (flag) {
        cin >> ts;
    }
    while (ts--) {
        ma1n(); 
    }
    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 0 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 1 ms 204 KB Output is correct
6 Correct 0 ms 204 KB Output is correct
7 Correct 1 ms 204 KB Output is correct
8 Correct 0 ms 204 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 27 ms 316 KB Output is correct
2 Correct 6 ms 204 KB Output is correct
3 Correct 18 ms 312 KB Output is correct
4 Correct 16 ms 308 KB Output is correct
5 Correct 20 ms 204 KB Output is correct
6 Correct 15 ms 204 KB Output is correct
7 Correct 3 ms 204 KB Output is correct
8 Correct 15 ms 312 KB Output is correct
9 Correct 34 ms 204 KB Output is correct
10 Correct 19 ms 316 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 1 ms 308 KB Output is correct
4 Correct 1 ms 324 KB Output is correct
5 Correct 1 ms 320 KB Output is correct
6 Correct 1 ms 204 KB Output is correct
7 Correct 1 ms 204 KB Output is correct
8 Correct 1 ms 320 KB Output is correct
9 Correct 1 ms 204 KB Output is correct
10 Correct 1 ms 204 KB Output is correct
11 Correct 1 ms 312 KB Output is correct
12 Correct 1 ms 204 KB Output is correct
13 Correct 1 ms 244 KB Output is correct
14 Correct 1 ms 316 KB Output is correct
15 Correct 1 ms 204 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 1 ms 308 KB Output is correct
4 Correct 1 ms 324 KB Output is correct
5 Correct 1 ms 320 KB Output is correct
6 Correct 1 ms 204 KB Output is correct
7 Correct 1 ms 204 KB Output is correct
8 Correct 1 ms 320 KB Output is correct
9 Correct 1 ms 204 KB Output is correct
10 Correct 1 ms 204 KB Output is correct
11 Correct 1 ms 312 KB Output is correct
12 Correct 1 ms 204 KB Output is correct
13 Correct 1 ms 244 KB Output is correct
14 Correct 1 ms 316 KB Output is correct
15 Correct 1 ms 204 KB Output is correct
16 Correct 13 ms 716 KB Output is correct
17 Correct 29 ms 1436 KB Output is correct
18 Correct 50 ms 1348 KB Output is correct
19 Correct 220 ms 1284 KB Output is correct
20 Correct 246 ms 1268 KB Output is correct
21 Correct 28 ms 1340 KB Output is correct
22 Correct 1 ms 204 KB Output is correct
23 Correct 35 ms 928 KB Output is correct
24 Correct 44 ms 1260 KB Output is correct
25 Correct 8 ms 588 KB Output is correct
26 Correct 27 ms 1092 KB Output is correct
27 Correct 46 ms 1296 KB Output is correct
28 Correct 47 ms 1332 KB Output is correct
29 Correct 11 ms 808 KB Output is correct
30 Correct 2 ms 320 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 27 ms 316 KB Output is correct
2 Correct 6 ms 204 KB Output is correct
3 Correct 18 ms 312 KB Output is correct
4 Correct 16 ms 308 KB Output is correct
5 Correct 20 ms 204 KB Output is correct
6 Correct 15 ms 204 KB Output is correct
7 Correct 3 ms 204 KB Output is correct
8 Correct 15 ms 312 KB Output is correct
9 Correct 34 ms 204 KB Output is correct
10 Correct 19 ms 316 KB Output is correct
11 Correct 1 ms 204 KB Output is correct
12 Correct 1 ms 204 KB Output is correct
13 Correct 1 ms 308 KB Output is correct
14 Correct 1 ms 324 KB Output is correct
15 Correct 1 ms 320 KB Output is correct
16 Correct 1 ms 204 KB Output is correct
17 Correct 1 ms 204 KB Output is correct
18 Correct 1 ms 320 KB Output is correct
19 Correct 1 ms 204 KB Output is correct
20 Correct 1 ms 204 KB Output is correct
21 Correct 1 ms 312 KB Output is correct
22 Correct 1 ms 204 KB Output is correct
23 Correct 1 ms 244 KB Output is correct
24 Correct 1 ms 316 KB Output is correct
25 Correct 1 ms 204 KB Output is correct
26 Correct 13 ms 716 KB Output is correct
27 Correct 29 ms 1436 KB Output is correct
28 Correct 50 ms 1348 KB Output is correct
29 Correct 220 ms 1284 KB Output is correct
30 Correct 246 ms 1268 KB Output is correct
31 Correct 28 ms 1340 KB Output is correct
32 Correct 1 ms 204 KB Output is correct
33 Correct 35 ms 928 KB Output is correct
34 Correct 44 ms 1260 KB Output is correct
35 Correct 8 ms 588 KB Output is correct
36 Correct 27 ms 1092 KB Output is correct
37 Correct 46 ms 1296 KB Output is correct
38 Correct 47 ms 1332 KB Output is correct
39 Correct 11 ms 808 KB Output is correct
40 Correct 2 ms 320 KB Output is correct
41 Correct 201 ms 1304 KB Output is correct
42 Correct 56 ms 1348 KB Output is correct
43 Correct 109 ms 1348 KB Output is correct
44 Correct 52 ms 1384 KB Output is correct
45 Correct 39 ms 1348 KB Output is correct
46 Correct 224 ms 1352 KB Output is correct
47 Correct 34 ms 1348 KB Output is correct
48 Correct 82 ms 1328 KB Output is correct
49 Correct 53 ms 1348 KB Output is correct
50 Correct 1074 ms 1476 KB Output is correct
51 Correct 1134 ms 1348 KB Output is correct
52 Correct 1050 ms 1400 KB Output is correct
53 Correct 1113 ms 1380 KB Output is correct
54 Correct 1048 ms 1336 KB Output is correct
55 Correct 1154 ms 1380 KB Output is correct
56 Correct 1004 ms 1388 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 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 1 ms 204 KB Output is correct
6 Correct 0 ms 204 KB Output is correct
7 Correct 1 ms 204 KB Output is correct
8 Correct 0 ms 204 KB Output is correct
9 Correct 27 ms 316 KB Output is correct
10 Correct 6 ms 204 KB Output is correct
11 Correct 18 ms 312 KB Output is correct
12 Correct 16 ms 308 KB Output is correct
13 Correct 20 ms 204 KB Output is correct
14 Correct 15 ms 204 KB Output is correct
15 Correct 3 ms 204 KB Output is correct
16 Correct 15 ms 312 KB Output is correct
17 Correct 34 ms 204 KB Output is correct
18 Correct 19 ms 316 KB Output is correct
19 Correct 1 ms 204 KB Output is correct
20 Correct 1 ms 204 KB Output is correct
21 Correct 1 ms 308 KB Output is correct
22 Correct 1 ms 324 KB Output is correct
23 Correct 1 ms 320 KB Output is correct
24 Correct 1 ms 204 KB Output is correct
25 Correct 1 ms 204 KB Output is correct
26 Correct 1 ms 320 KB Output is correct
27 Correct 1 ms 204 KB Output is correct
28 Correct 1 ms 204 KB Output is correct
29 Correct 1 ms 312 KB Output is correct
30 Correct 1 ms 204 KB Output is correct
31 Correct 1 ms 244 KB Output is correct
32 Correct 1 ms 316 KB Output is correct
33 Correct 1 ms 204 KB Output is correct
34 Correct 13 ms 716 KB Output is correct
35 Correct 29 ms 1436 KB Output is correct
36 Correct 50 ms 1348 KB Output is correct
37 Correct 220 ms 1284 KB Output is correct
38 Correct 246 ms 1268 KB Output is correct
39 Correct 28 ms 1340 KB Output is correct
40 Correct 1 ms 204 KB Output is correct
41 Correct 35 ms 928 KB Output is correct
42 Correct 44 ms 1260 KB Output is correct
43 Correct 8 ms 588 KB Output is correct
44 Correct 27 ms 1092 KB Output is correct
45 Correct 46 ms 1296 KB Output is correct
46 Correct 47 ms 1332 KB Output is correct
47 Correct 11 ms 808 KB Output is correct
48 Correct 2 ms 320 KB Output is correct
49 Correct 201 ms 1304 KB Output is correct
50 Correct 56 ms 1348 KB Output is correct
51 Correct 109 ms 1348 KB Output is correct
52 Correct 52 ms 1384 KB Output is correct
53 Correct 39 ms 1348 KB Output is correct
54 Correct 224 ms 1352 KB Output is correct
55 Correct 34 ms 1348 KB Output is correct
56 Correct 82 ms 1328 KB Output is correct
57 Correct 53 ms 1348 KB Output is correct
58 Correct 1074 ms 1476 KB Output is correct
59 Correct 1134 ms 1348 KB Output is correct
60 Correct 1050 ms 1400 KB Output is correct
61 Correct 1113 ms 1380 KB Output is correct
62 Correct 1048 ms 1336 KB Output is correct
63 Correct 1154 ms 1380 KB Output is correct
64 Correct 1004 ms 1388 KB Output is correct
65 Correct 1 ms 332 KB Output is correct
66 Correct 1 ms 204 KB Output is correct
67 Correct 1093 ms 2464 KB Output is correct
68 Correct 1092 ms 2504 KB Output is correct
69 Correct 950 ms 2236 KB Output is correct
70 Correct 1071 ms 2460 KB Output is correct
71 Correct 1059 ms 2432 KB Output is correct
72 Correct 1033 ms 2372 KB Output is correct
73 Correct 993 ms 2324 KB Output is correct
74 Correct 1069 ms 2588 KB Output is correct
75 Correct 1052 ms 2368 KB Output is correct
76 Correct 1114 ms 2600 KB Output is correct
77 Correct 165 ms 2588 KB Output is correct
78 Correct 52 ms 2348 KB Output is correct
79 Correct 109 ms 2196 KB Output is correct
80 Correct 115 ms 2324 KB Output is correct
81 Correct 105 ms 2204 KB Output is correct
82 Correct 88 ms 2488 KB Output is correct
83 Correct 64 ms 2328 KB Output is correct
84 Correct 653 ms 2716 KB Output is correct
85 Correct 1153 ms 2600 KB Output is correct
86 Correct 1 ms 204 KB Output is correct
87 Correct 1 ms 312 KB Output is correct
88 Correct 1184 ms 2724 KB Output is correct
89 Correct 220 ms 664 KB Output is correct
90 Correct 0 ms 204 KB Output is correct