Submission #495249

# Submission time Handle Problem Language Result Execution time Memory
495249 2021-12-18T08:00:03 Z kingline Chessboard (IZhO18_chessboard) C++17
0 / 100
2 ms 716 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 = 1e3 + 5;

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

main() {
    /*ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);*/
    cin >> n >> k;
    for(int kk = 1; kk <= k; kk++) {
        int xx, yy;
        cin >> x[kk] >> y[kk] >> xx >> yy;
        pref[x[kk]][y[kk]] = 1;
    }
    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];
            //cout << pref[i][j] << " ";
        }
        //cout << endl;
    }
    vector < int > dv;
    dv.pb(1);
    for(int i = 2; i <= sqrt(n); i++) {
        if(n % i == 0) {
            dv.pb(i);
            if(n / i != i) dv.pb(n / i);
        }
    }
    sort(all(dv));
    if(dv.size() == 1) {
        int odd = 0, even = 0;
        for(int i = 1; i <= k; i++) {
            if(x[i] % 2 == y[i] % 2) odd++;
            else even++;
        }
        cout << (n * n + 1 ) / 2 - max(even, odd) + min(even, odd);
        return 0;
    }
    long long ans = n * n * n;
    for(int v = 0; v < dv.size(); v++) {
        int z = dv[v];
        int type = 1;
        long long res1 = 0, res2 = 0;
        for(int i = z; i <= n; i += z) {
            if(i > n) break;
            for(int j = z; j <= n; j += z) {
                if(j > n) break;
                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:18:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
   18 | main() {
      | ^~~~
chessboard.cpp: In function 'int main()':
chessboard.cpp:54:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   54 |     for(int v = 0; v < dv.size(); v++) {
      |                    ~~^~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 0 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 Incorrect 1 ms 716 KB Output isn't correct
6 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 1 ms 332 KB Execution killed with signal 11
2 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 2 ms 588 KB Output is correct
4 Correct 1 ms 588 KB Output is correct
5 Correct 1 ms 604 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 2 ms 588 KB Output is correct
4 Correct 1 ms 588 KB Output is correct
5 Correct 1 ms 604 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 Runtime error 1 ms 332 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 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 Incorrect 1 ms 716 KB Output isn't correct
6 Halted 0 ms 0 KB -