Submission #495275

# Submission time Handle Problem Language Result Execution time Memory
495275 2021-12-18T08:22:51 Z kingline Chessboard (IZhO18_chessboard) C++17
16 / 100
90 ms 1692 KB
#include <bits/stdc++.h>
#define pb push_back
#define ios ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define all(data) data.begin() , data.end()
#define endl '\n'
//freopen("nenokku_easy.in", "r", stdin);
//freopen("nenokku_easy.out", "w", stdout);
#define int long long

using namespace std;

typedef long long ll;
const int N = 1e5 + 5;

int n, k, y[N], x[N], pref[1005][1005];

main() {
    /*ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);*/
    cin >> n >> k;
    bool pr = 1;
    for(int i = 2; i <= sqrt(n); i++) {
        if(n % i == 0) pr = 0;
    }
    if(pr) {
        int even = 0, odd = 0;
        for(int i = 1; i <= k; i++) {
            int xx, yy;
            cin >> x[i] >> y[i] >> xx >> yy;
            if(xx % 2 == yy % 2) ++odd;
            else even++;
        }
        int ev = (n * n + 1) / 2, od = (n * n) / 2;
        cout << min(ev - odd + even, od - even + odd);
    } else {
        for(int kk = 1; kk <= k; kk++) {
            int x, y, xx, yy;
            cin >> x >> y >> xx >> yy;
            for(int i = x; i <= xx; i++) {
                for(int j = y; j <= yy; j++) {
                    pref[i][j]++;
                }
            }
        }
        for(int i = 1; i <= n; i++) {
            for(int j = 1; j <= n; j++) {
                pref[i][j] += pref[i - 1][j] + pref[i][j - 1] - pref[i - 1][j - 1];
            }
        }
        int ans = n * n * n;
        for(int z = 1; z <= (n >> 1); z++) {
            if(n % z == 0) {
                bool type = 1;
                int res1 = 0, res2 = 0;
                for(int i = z; i <= n; i += z) {
                    for(int j = z; j <= n; j += z) {
                        if(type) {
                            res1 += pref[i][j] - pref[i][j - z] - pref[i - z][j] + pref[i - z][j - z];
                            res2 += z * z - (pref[i][j] - pref[i][j - z] - pref[i - z][j] + pref[i - z][j - z]);
                        } else {
                            res1 += z * z - (pref[i][j] - pref[i][j - z] - pref[i - z][j] + pref[i - z][j - z]);
                            res2 += pref[i][j] - pref[i][j - z] - pref[i - z][j] + pref[i - z][j - z];
                        }
                        type = 1 - type;
                    }
                }
                ans = min(ans, min(res1, res2));
            }
        }
        cout << ans;
    }
}

/*
5
2 8 5 1 10
5
2 3 5 3
2 5 3 3
1 4 4
2 3 4 2
1 1 2
*/






Compilation message

chessboard.cpp:17:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
   17 | main() {
      | ^~~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 716 KB Output is correct
3 Correct 1 ms 716 KB Output is correct
4 Correct 1 ms 716 KB Output is correct
5 Correct 1 ms 204 KB Output is correct
6 Correct 1 ms 716 KB Output is correct
7 Correct 1 ms 716 KB Output is correct
8 Correct 1 ms 716 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 70 ms 1260 KB Output is correct
2 Correct 19 ms 508 KB Output is correct
3 Correct 40 ms 816 KB Output is correct
4 Correct 39 ms 960 KB Output is correct
5 Correct 80 ms 1104 KB Output is correct
6 Correct 43 ms 744 KB Output is correct
7 Correct 8 ms 332 KB Output is correct
8 Correct 35 ms 732 KB Output is correct
9 Correct 90 ms 1692 KB Output is correct
10 Correct 57 ms 1064 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 588 KB Output is correct
2 Correct 1 ms 588 KB Output is correct
3 Correct 1 ms 588 KB Output is correct
4 Correct 1 ms 588 KB Output is correct
5 Correct 1 ms 588 KB Output is correct
6 Incorrect 1 ms 588 KB Output isn't correct
7 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 588 KB Output is correct
2 Correct 1 ms 588 KB Output is correct
3 Correct 1 ms 588 KB Output is correct
4 Correct 1 ms 588 KB Output is correct
5 Correct 1 ms 588 KB Output is correct
6 Incorrect 1 ms 588 KB Output isn't correct
7 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 70 ms 1260 KB Output is correct
2 Correct 19 ms 508 KB Output is correct
3 Correct 40 ms 816 KB Output is correct
4 Correct 39 ms 960 KB Output is correct
5 Correct 80 ms 1104 KB Output is correct
6 Correct 43 ms 744 KB Output is correct
7 Correct 8 ms 332 KB Output is correct
8 Correct 35 ms 732 KB Output is correct
9 Correct 90 ms 1692 KB Output is correct
10 Correct 57 ms 1064 KB Output is correct
11 Correct 1 ms 588 KB Output is correct
12 Correct 1 ms 588 KB Output is correct
13 Correct 1 ms 588 KB Output is correct
14 Correct 1 ms 588 KB Output is correct
15 Correct 1 ms 588 KB Output is correct
16 Incorrect 1 ms 588 KB Output isn't correct
17 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 716 KB Output is correct
3 Correct 1 ms 716 KB Output is correct
4 Correct 1 ms 716 KB Output is correct
5 Correct 1 ms 204 KB Output is correct
6 Correct 1 ms 716 KB Output is correct
7 Correct 1 ms 716 KB Output is correct
8 Correct 1 ms 716 KB Output is correct
9 Correct 70 ms 1260 KB Output is correct
10 Correct 19 ms 508 KB Output is correct
11 Correct 40 ms 816 KB Output is correct
12 Correct 39 ms 960 KB Output is correct
13 Correct 80 ms 1104 KB Output is correct
14 Correct 43 ms 744 KB Output is correct
15 Correct 8 ms 332 KB Output is correct
16 Correct 35 ms 732 KB Output is correct
17 Correct 90 ms 1692 KB Output is correct
18 Correct 57 ms 1064 KB Output is correct
19 Correct 1 ms 588 KB Output is correct
20 Correct 1 ms 588 KB Output is correct
21 Correct 1 ms 588 KB Output is correct
22 Correct 1 ms 588 KB Output is correct
23 Correct 1 ms 588 KB Output is correct
24 Incorrect 1 ms 588 KB Output isn't correct
25 Halted 0 ms 0 KB -