답안 #962455

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
962455 2024-04-13T15:07:51 Z Cookie Chessboard (IZhO18_chessboard) C++14
70 / 100
528 ms 16640 KB
#include<bits/stdc++.h>
#include<fstream>
using namespace std;
#define sz(a) (int)a.size()
#define ALL(v) v.begin(), v.end()
#define ALLR(v) v.rbegin(), v.rend()
#define ll long long
#define pb push_back
#define forr(i, a, b) for(int i = a; i < b; i++)
#define dorr(i, a, b) for(int i = a; i >= b; i--)
#define ld long double
#define vt vector
#include<fstream>
#define fi first
#define se second
#define pll pair<ll, ll>
#define pii pair<int, int>
#define mpp make_pair
const ld PI = 3.14159265359, prec = 1e-9;;
//using u128 = __uint128_t;
//const int x[4] = {1, 0, -1, 0};
//const int y[4] = {0, -1, 0, 1};
const ll mod = 1e9 + 7, pr = 31;
const int mxn = 5e5 + 5, mxq = 1e5 + 5, sq = 450, mxv = 5e4 + 1;
//const int base = (1 <<18);
const ll inf = 1e10 + 5, neg = -69420, inf2 = 1e14;
mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
// have fun!
ll n, k;
ll ans = inf;
ll x[mxn + 1], y[mxn + 1], x2[mxn + 1], y2[mxn + 1];
ll cntodd(ll l, ll r){
    return((r + 1) / 2 - l / 2);
}
ll cnteven(ll l, ll r){
    return((r + 2) / 2 - (l + 1) / 2);
}
pll get(ll l, ll r, ll k){
    ll lw = (l + k - 1) / k, hg = (r - k + 1) / k;
   
    ll odd = 0, even = 0;
    if(r < k || lw == hg + 2){
        if((r / k) & 1)odd += r - l + 1;
        else even += r - l + 1;
        return(mpp(odd, even));
    }
    odd += cntodd(lw, hg) * k; even += cnteven(lw, hg) * k;
    
    if(l % k != 0){
        if((l / k) & 1){
            odd += (k - (l % k));
        }else{
            even += (k - (l % k));
        }
    }if(r % k != k - 1){
        if((r / k) & 1){
            odd += (r % k) + 1;
        }else{
            even += (r % k) + 1;
        }
    }
    
    return(mpp(odd, even));
}
ll area = 0;
void solve(int cand){
    
    ll odd = 0, even = 0;
    for(int i = 1; i <= k; i++){
        pll col = get(y[i], y2[i], cand), row = get(x[i], x2[i], cand);
        //cout << col.fi << " " << col.se << " " << row.fi << " " << row.se << "\n";
        odd += col.fi * row.se + col.se * row.fi; even += col.fi * row.fi + col.se * row.se;
        
    }
    ll totodd = 0, toteven = 0;
    if((n / cand) & 1){
        toteven = (n * n / (cand * cand) + 1) / 2 * cand * cand;
        totodd = (n * n / (cand * cand)) / 2 * cand * cand;
    }else{
        toteven = (n * n / (cand * cand)) / 2 * cand * cand;
        totodd = (n * n / (cand * cand)) / 2 * cand * cand;
    }
    assert(even + odd == area);
    //cout << cand << " " << even << " " << odd << "\n";
    ans = min(ans, min(abs(toteven - even) + area - even, abs(totodd - odd) + area - odd));
}
void solve(){
    cin >> n >> k;
    for(int i = 1; i <= k; i++){
        cin >> x[i] >> y[i] >> x2[i] >> y2[i]; --x[i]; --y[i]; --x2[i]; --y2[i];
        area += (y2[i] - y[i] + 1) * (x2[i] - x[i] + 1);
    }
    for(int i = 1; i < n; i++){
        if(n % i == 0){
            solve(i);
        }
    }
    cout << ans;
}
signed main(){
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    //freopen("netw.inp", "r", stdin);
    //freopen("netw.out", "w", stdout)
    int tt; tt = 1;
    while(tt--){
        solve();
 
    }
    return(0);
}
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 1 ms 352 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Correct 1 ms 352 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 1 ms 440 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 20 ms 11860 KB Output is correct
2 Correct 6 ms 7012 KB Output is correct
3 Correct 14 ms 9708 KB Output is correct
4 Correct 15 ms 9564 KB Output is correct
5 Correct 18 ms 11924 KB Output is correct
6 Correct 11 ms 9404 KB Output is correct
7 Correct 4 ms 6748 KB Output is correct
8 Correct 12 ms 9624 KB Output is correct
9 Correct 32 ms 14160 KB Output is correct
10 Correct 20 ms 11516 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 6612 KB Output is correct
2 Correct 1 ms 6612 KB Output is correct
3 Correct 2 ms 6488 KB Output is correct
4 Correct 1 ms 6492 KB Output is correct
5 Correct 1 ms 6492 KB Output is correct
6 Correct 1 ms 6492 KB Output is correct
7 Correct 2 ms 6636 KB Output is correct
8 Correct 1 ms 6492 KB Output is correct
9 Correct 3 ms 6492 KB Output is correct
10 Correct 1 ms 6744 KB Output is correct
11 Correct 1 ms 6492 KB Output is correct
12 Correct 1 ms 6492 KB Output is correct
13 Correct 2 ms 6620 KB Output is correct
14 Correct 1 ms 6492 KB Output is correct
15 Correct 1 ms 6492 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 6612 KB Output is correct
2 Correct 1 ms 6612 KB Output is correct
3 Correct 2 ms 6488 KB Output is correct
4 Correct 1 ms 6492 KB Output is correct
5 Correct 1 ms 6492 KB Output is correct
6 Correct 1 ms 6492 KB Output is correct
7 Correct 2 ms 6636 KB Output is correct
8 Correct 1 ms 6492 KB Output is correct
9 Correct 3 ms 6492 KB Output is correct
10 Correct 1 ms 6744 KB Output is correct
11 Correct 1 ms 6492 KB Output is correct
12 Correct 1 ms 6492 KB Output is correct
13 Correct 2 ms 6620 KB Output is correct
14 Correct 1 ms 6492 KB Output is correct
15 Correct 1 ms 6492 KB Output is correct
16 Correct 10 ms 9052 KB Output is correct
17 Correct 30 ms 13908 KB Output is correct
18 Correct 42 ms 16004 KB Output is correct
19 Correct 113 ms 13992 KB Output is correct
20 Correct 123 ms 15952 KB Output is correct
21 Correct 22 ms 13824 KB Output is correct
22 Correct 2 ms 6492 KB Output is correct
23 Correct 21 ms 9256 KB Output is correct
24 Correct 30 ms 13908 KB Output is correct
25 Correct 5 ms 6748 KB Output is correct
26 Correct 20 ms 11644 KB Output is correct
27 Correct 31 ms 11664 KB Output is correct
28 Correct 31 ms 13952 KB Output is correct
29 Correct 9 ms 9308 KB Output is correct
30 Correct 2 ms 6492 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 20 ms 11860 KB Output is correct
2 Correct 6 ms 7012 KB Output is correct
3 Correct 14 ms 9708 KB Output is correct
4 Correct 15 ms 9564 KB Output is correct
5 Correct 18 ms 11924 KB Output is correct
6 Correct 11 ms 9404 KB Output is correct
7 Correct 4 ms 6748 KB Output is correct
8 Correct 12 ms 9624 KB Output is correct
9 Correct 32 ms 14160 KB Output is correct
10 Correct 20 ms 11516 KB Output is correct
11 Correct 2 ms 6612 KB Output is correct
12 Correct 1 ms 6612 KB Output is correct
13 Correct 2 ms 6488 KB Output is correct
14 Correct 1 ms 6492 KB Output is correct
15 Correct 1 ms 6492 KB Output is correct
16 Correct 1 ms 6492 KB Output is correct
17 Correct 2 ms 6636 KB Output is correct
18 Correct 1 ms 6492 KB Output is correct
19 Correct 3 ms 6492 KB Output is correct
20 Correct 1 ms 6744 KB Output is correct
21 Correct 1 ms 6492 KB Output is correct
22 Correct 1 ms 6492 KB Output is correct
23 Correct 2 ms 6620 KB Output is correct
24 Correct 1 ms 6492 KB Output is correct
25 Correct 1 ms 6492 KB Output is correct
26 Correct 10 ms 9052 KB Output is correct
27 Correct 30 ms 13908 KB Output is correct
28 Correct 42 ms 16004 KB Output is correct
29 Correct 113 ms 13992 KB Output is correct
30 Correct 123 ms 15952 KB Output is correct
31 Correct 22 ms 13824 KB Output is correct
32 Correct 2 ms 6492 KB Output is correct
33 Correct 21 ms 9256 KB Output is correct
34 Correct 30 ms 13908 KB Output is correct
35 Correct 5 ms 6748 KB Output is correct
36 Correct 20 ms 11644 KB Output is correct
37 Correct 31 ms 11664 KB Output is correct
38 Correct 31 ms 13952 KB Output is correct
39 Correct 9 ms 9308 KB Output is correct
40 Correct 2 ms 6492 KB Output is correct
41 Correct 99 ms 14000 KB Output is correct
42 Correct 37 ms 14036 KB Output is correct
43 Correct 60 ms 14168 KB Output is correct
44 Correct 40 ms 14164 KB Output is correct
45 Correct 35 ms 16308 KB Output is correct
46 Correct 108 ms 13972 KB Output is correct
47 Correct 27 ms 14024 KB Output is correct
48 Correct 49 ms 14180 KB Output is correct
49 Correct 38 ms 14164 KB Output is correct
50 Correct 473 ms 14216 KB Output is correct
51 Correct 516 ms 16640 KB Output is correct
52 Correct 472 ms 14420 KB Output is correct
53 Correct 503 ms 16208 KB Output is correct
54 Correct 469 ms 14212 KB Output is correct
55 Correct 522 ms 16516 KB Output is correct
56 Correct 448 ms 14212 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 1 ms 352 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Correct 1 ms 352 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 1 ms 440 KB Output is correct
9 Correct 20 ms 11860 KB Output is correct
10 Correct 6 ms 7012 KB Output is correct
11 Correct 14 ms 9708 KB Output is correct
12 Correct 15 ms 9564 KB Output is correct
13 Correct 18 ms 11924 KB Output is correct
14 Correct 11 ms 9404 KB Output is correct
15 Correct 4 ms 6748 KB Output is correct
16 Correct 12 ms 9624 KB Output is correct
17 Correct 32 ms 14160 KB Output is correct
18 Correct 20 ms 11516 KB Output is correct
19 Correct 2 ms 6612 KB Output is correct
20 Correct 1 ms 6612 KB Output is correct
21 Correct 2 ms 6488 KB Output is correct
22 Correct 1 ms 6492 KB Output is correct
23 Correct 1 ms 6492 KB Output is correct
24 Correct 1 ms 6492 KB Output is correct
25 Correct 2 ms 6636 KB Output is correct
26 Correct 1 ms 6492 KB Output is correct
27 Correct 3 ms 6492 KB Output is correct
28 Correct 1 ms 6744 KB Output is correct
29 Correct 1 ms 6492 KB Output is correct
30 Correct 1 ms 6492 KB Output is correct
31 Correct 2 ms 6620 KB Output is correct
32 Correct 1 ms 6492 KB Output is correct
33 Correct 1 ms 6492 KB Output is correct
34 Correct 10 ms 9052 KB Output is correct
35 Correct 30 ms 13908 KB Output is correct
36 Correct 42 ms 16004 KB Output is correct
37 Correct 113 ms 13992 KB Output is correct
38 Correct 123 ms 15952 KB Output is correct
39 Correct 22 ms 13824 KB Output is correct
40 Correct 2 ms 6492 KB Output is correct
41 Correct 21 ms 9256 KB Output is correct
42 Correct 30 ms 13908 KB Output is correct
43 Correct 5 ms 6748 KB Output is correct
44 Correct 20 ms 11644 KB Output is correct
45 Correct 31 ms 11664 KB Output is correct
46 Correct 31 ms 13952 KB Output is correct
47 Correct 9 ms 9308 KB Output is correct
48 Correct 2 ms 6492 KB Output is correct
49 Correct 99 ms 14000 KB Output is correct
50 Correct 37 ms 14036 KB Output is correct
51 Correct 60 ms 14168 KB Output is correct
52 Correct 40 ms 14164 KB Output is correct
53 Correct 35 ms 16308 KB Output is correct
54 Correct 108 ms 13972 KB Output is correct
55 Correct 27 ms 14024 KB Output is correct
56 Correct 49 ms 14180 KB Output is correct
57 Correct 38 ms 14164 KB Output is correct
58 Correct 473 ms 14216 KB Output is correct
59 Correct 516 ms 16640 KB Output is correct
60 Correct 472 ms 14420 KB Output is correct
61 Correct 503 ms 16208 KB Output is correct
62 Correct 469 ms 14212 KB Output is correct
63 Correct 522 ms 16516 KB Output is correct
64 Correct 448 ms 14212 KB Output is correct
65 Correct 1 ms 6492 KB Output is correct
66 Correct 1 ms 6492 KB Output is correct
67 Correct 520 ms 14220 KB Output is correct
68 Correct 521 ms 14220 KB Output is correct
69 Correct 458 ms 14212 KB Output is correct
70 Correct 504 ms 14212 KB Output is correct
71 Correct 497 ms 14208 KB Output is correct
72 Correct 497 ms 14208 KB Output is correct
73 Correct 478 ms 14208 KB Output is correct
74 Correct 510 ms 14208 KB Output is correct
75 Correct 498 ms 14164 KB Output is correct
76 Correct 528 ms 14420 KB Output is correct
77 Incorrect 91 ms 16468 KB Output isn't correct
78 Halted 0 ms 0 KB -