답안 #911125

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
911125 2024-01-18T13:26:11 Z GrindMachine Chessboard (IZhO18_chessboard) C++17
100 / 100
150 ms 6620 KB
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace std;
using namespace __gnu_pbds;

template<typename T> using Tree = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
typedef long long int ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;

#define fastio ios_base::sync_with_stdio(false); cin.tie(NULL)
#define pb push_back
#define endl '\n'
#define sz(a) (int)a.size()
#define setbits(x) __builtin_popcountll(x)
#define ff first
#define ss second
#define conts continue
#define ceil2(x,y) ((x+y-1)/(y))
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define yes cout << "Yes" << endl
#define no cout << "No" << endl

#define rep(i,n) for(int i = 0; i < n; ++i)
#define rep1(i,n) for(int i = 1; i <= n; ++i)
#define rev(i,s,e) for(int i = s; i >= e; --i)
#define trav(i,a) for(auto &i : a)

template<typename T>
void amin(T &a, T b) {
    a = min(a,b);
}

template<typename T>
void amax(T &a, T b) {
    a = max(a,b);
}

#ifdef LOCAL
#include "debug.h"
#else
#define debug(x) 42
#endif

/*



*/

const int MOD = 1e9 + 7;
const int N = 1e5 + 5;
const int inf1 = int(1e9) + 5;
const ll inf2 = ll(1e18) + 5;

void solve(int test_case)
{
    ll n,m; cin >> n >> m;
    vector<array<ll,4>> a(m);
    rep(i,m) rep(j,4) cin >> a[i][j], a[i][j]--;

    vector<ll> p(n+5);
    ll ans = inf2;

    rep1(k,n-1){
        if(n%k) conts;

        rep1(i,n){
            p[i] = p[i-1];
            if(((i-1)/k)&1){
                p[i]++;
            }
        }

        ll curr_ans = 0;

        rep(i,m){
            auto [x1,y1,x2,y2] = a[i];

            ll row_odd = p[x2+1]-p[x1];
            ll row_even = x2-x1+1-row_odd;
            ll col_odd = p[y2+1]-p[y1];
            ll col_even = y2-y1+1-col_odd;

            curr_ans -= (row_odd*col_even)+(row_even*col_odd);
            curr_ans += (row_odd*col_odd)+(row_even*col_even);
        }

        ll cnt = n/k;
        ll black = ceil2(cnt,2)*(cnt/2)*2*k*k;
        curr_ans += black;

        curr_ans = min(curr_ans,n*n-curr_ans);
        amin(ans,curr_ans);
    }

    cout << ans << endl;
}

int main()
{
    fastio;

    int t = 1;
    // cin >> t;

    rep1(i, t) {
        solve(i);
    }

    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 344 KB Output is correct
8 Correct 1 ms 348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 17 ms 4176 KB Output is correct
2 Correct 5 ms 1372 KB Output is correct
3 Correct 12 ms 3164 KB Output is correct
4 Correct 11 ms 2648 KB Output is correct
5 Correct 15 ms 3824 KB Output is correct
6 Correct 10 ms 2652 KB Output is correct
7 Correct 3 ms 856 KB Output is correct
8 Correct 10 ms 2648 KB Output is correct
9 Correct 27 ms 5952 KB Output is correct
10 Correct 14 ms 3420 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 1 ms 604 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
7 Correct 1 ms 460 KB Output is correct
8 Correct 1 ms 348 KB Output is correct
9 Correct 1 ms 388 KB Output is correct
10 Correct 1 ms 348 KB Output is correct
11 Correct 1 ms 348 KB Output is correct
12 Correct 1 ms 344 KB Output is correct
13 Correct 1 ms 348 KB Output is correct
14 Correct 1 ms 500 KB Output is correct
15 Correct 1 ms 348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 1 ms 604 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
7 Correct 1 ms 460 KB Output is correct
8 Correct 1 ms 348 KB Output is correct
9 Correct 1 ms 388 KB Output is correct
10 Correct 1 ms 348 KB Output is correct
11 Correct 1 ms 348 KB Output is correct
12 Correct 1 ms 344 KB Output is correct
13 Correct 1 ms 348 KB Output is correct
14 Correct 1 ms 500 KB Output is correct
15 Correct 1 ms 348 KB Output is correct
16 Correct 7 ms 1624 KB Output is correct
17 Correct 18 ms 4444 KB Output is correct
18 Correct 23 ms 4952 KB Output is correct
19 Correct 25 ms 4620 KB Output is correct
20 Correct 30 ms 4948 KB Output is correct
21 Correct 18 ms 4128 KB Output is correct
22 Correct 1 ms 344 KB Output is correct
23 Correct 11 ms 2392 KB Output is correct
24 Correct 20 ms 4700 KB Output is correct
25 Correct 3 ms 864 KB Output is correct
26 Correct 15 ms 2908 KB Output is correct
27 Correct 16 ms 3676 KB Output is correct
28 Correct 20 ms 4820 KB Output is correct
29 Correct 9 ms 1892 KB Output is correct
30 Correct 1 ms 348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 17 ms 4176 KB Output is correct
2 Correct 5 ms 1372 KB Output is correct
3 Correct 12 ms 3164 KB Output is correct
4 Correct 11 ms 2648 KB Output is correct
5 Correct 15 ms 3824 KB Output is correct
6 Correct 10 ms 2652 KB Output is correct
7 Correct 3 ms 856 KB Output is correct
8 Correct 10 ms 2648 KB Output is correct
9 Correct 27 ms 5952 KB Output is correct
10 Correct 14 ms 3420 KB Output is correct
11 Correct 1 ms 344 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 1 ms 348 KB Output is correct
14 Correct 1 ms 604 KB Output is correct
15 Correct 1 ms 348 KB Output is correct
16 Correct 1 ms 348 KB Output is correct
17 Correct 1 ms 460 KB Output is correct
18 Correct 1 ms 348 KB Output is correct
19 Correct 1 ms 388 KB Output is correct
20 Correct 1 ms 348 KB Output is correct
21 Correct 1 ms 348 KB Output is correct
22 Correct 1 ms 344 KB Output is correct
23 Correct 1 ms 348 KB Output is correct
24 Correct 1 ms 500 KB Output is correct
25 Correct 1 ms 348 KB Output is correct
26 Correct 7 ms 1624 KB Output is correct
27 Correct 18 ms 4444 KB Output is correct
28 Correct 23 ms 4952 KB Output is correct
29 Correct 25 ms 4620 KB Output is correct
30 Correct 30 ms 4948 KB Output is correct
31 Correct 18 ms 4128 KB Output is correct
32 Correct 1 ms 344 KB Output is correct
33 Correct 11 ms 2392 KB Output is correct
34 Correct 20 ms 4700 KB Output is correct
35 Correct 3 ms 864 KB Output is correct
36 Correct 15 ms 2908 KB Output is correct
37 Correct 16 ms 3676 KB Output is correct
38 Correct 20 ms 4820 KB Output is correct
39 Correct 9 ms 1892 KB Output is correct
40 Correct 1 ms 348 KB Output is correct
41 Correct 44 ms 5876 KB Output is correct
42 Correct 32 ms 6232 KB Output is correct
43 Correct 35 ms 5752 KB Output is correct
44 Correct 27 ms 6228 KB Output is correct
45 Correct 27 ms 6504 KB Output is correct
46 Correct 47 ms 6240 KB Output is correct
47 Correct 24 ms 5708 KB Output is correct
48 Correct 29 ms 5984 KB Output is correct
49 Correct 31 ms 5636 KB Output is correct
50 Correct 133 ms 6112 KB Output is correct
51 Correct 131 ms 6576 KB Output is correct
52 Correct 138 ms 6088 KB Output is correct
53 Correct 133 ms 6232 KB Output is correct
54 Correct 127 ms 6008 KB Output is correct
55 Correct 145 ms 6620 KB Output is correct
56 Correct 125 ms 5852 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 344 KB Output is correct
8 Correct 1 ms 348 KB Output is correct
9 Correct 17 ms 4176 KB Output is correct
10 Correct 5 ms 1372 KB Output is correct
11 Correct 12 ms 3164 KB Output is correct
12 Correct 11 ms 2648 KB Output is correct
13 Correct 15 ms 3824 KB Output is correct
14 Correct 10 ms 2652 KB Output is correct
15 Correct 3 ms 856 KB Output is correct
16 Correct 10 ms 2648 KB Output is correct
17 Correct 27 ms 5952 KB Output is correct
18 Correct 14 ms 3420 KB Output is correct
19 Correct 1 ms 344 KB Output is correct
20 Correct 0 ms 348 KB Output is correct
21 Correct 1 ms 348 KB Output is correct
22 Correct 1 ms 604 KB Output is correct
23 Correct 1 ms 348 KB Output is correct
24 Correct 1 ms 348 KB Output is correct
25 Correct 1 ms 460 KB Output is correct
26 Correct 1 ms 348 KB Output is correct
27 Correct 1 ms 388 KB Output is correct
28 Correct 1 ms 348 KB Output is correct
29 Correct 1 ms 348 KB Output is correct
30 Correct 1 ms 344 KB Output is correct
31 Correct 1 ms 348 KB Output is correct
32 Correct 1 ms 500 KB Output is correct
33 Correct 1 ms 348 KB Output is correct
34 Correct 7 ms 1624 KB Output is correct
35 Correct 18 ms 4444 KB Output is correct
36 Correct 23 ms 4952 KB Output is correct
37 Correct 25 ms 4620 KB Output is correct
38 Correct 30 ms 4948 KB Output is correct
39 Correct 18 ms 4128 KB Output is correct
40 Correct 1 ms 344 KB Output is correct
41 Correct 11 ms 2392 KB Output is correct
42 Correct 20 ms 4700 KB Output is correct
43 Correct 3 ms 864 KB Output is correct
44 Correct 15 ms 2908 KB Output is correct
45 Correct 16 ms 3676 KB Output is correct
46 Correct 20 ms 4820 KB Output is correct
47 Correct 9 ms 1892 KB Output is correct
48 Correct 1 ms 348 KB Output is correct
49 Correct 44 ms 5876 KB Output is correct
50 Correct 32 ms 6232 KB Output is correct
51 Correct 35 ms 5752 KB Output is correct
52 Correct 27 ms 6228 KB Output is correct
53 Correct 27 ms 6504 KB Output is correct
54 Correct 47 ms 6240 KB Output is correct
55 Correct 24 ms 5708 KB Output is correct
56 Correct 29 ms 5984 KB Output is correct
57 Correct 31 ms 5636 KB Output is correct
58 Correct 133 ms 6112 KB Output is correct
59 Correct 131 ms 6576 KB Output is correct
60 Correct 138 ms 6088 KB Output is correct
61 Correct 133 ms 6232 KB Output is correct
62 Correct 127 ms 6008 KB Output is correct
63 Correct 145 ms 6620 KB Output is correct
64 Correct 125 ms 5852 KB Output is correct
65 Correct 1 ms 348 KB Output is correct
66 Correct 1 ms 348 KB Output is correct
67 Correct 127 ms 6264 KB Output is correct
68 Correct 132 ms 6228 KB Output is correct
69 Correct 120 ms 5456 KB Output is correct
70 Correct 116 ms 6080 KB Output is correct
71 Correct 118 ms 6008 KB Output is correct
72 Correct 116 ms 5720 KB Output is correct
73 Correct 123 ms 5712 KB Output is correct
74 Correct 135 ms 6192 KB Output is correct
75 Correct 121 ms 5980 KB Output is correct
76 Correct 133 ms 6480 KB Output is correct
77 Correct 41 ms 6608 KB Output is correct
78 Correct 30 ms 5968 KB Output is correct
79 Correct 32 ms 5716 KB Output is correct
80 Correct 47 ms 5980 KB Output is correct
81 Correct 36 ms 5764 KB Output is correct
82 Correct 34 ms 6352 KB Output is correct
83 Correct 26 ms 5972 KB Output is correct
84 Correct 87 ms 6556 KB Output is correct
85 Correct 150 ms 6372 KB Output is correct
86 Correct 57 ms 1116 KB Output is correct
87 Correct 57 ms 1116 KB Output is correct
88 Correct 128 ms 6612 KB Output is correct
89 Correct 74 ms 2136 KB Output is correct
90 Correct 59 ms 860 KB Output is correct