Submission #496381

# Submission time Handle Problem Language Result Execution time Memory
496381 2021-12-21T06:40:17 Z kingline Chessboard (IZhO18_chessboard) C++17
39 / 100
77 ms 1096 KB
/*#pragma GCC optimize("O3")
#pragma GCC target ("avx2")
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#pragma GCC optimize("unroll-loops")*/
#include <bits/stdc++.h>
#define file(data) freopen(data".in", "r", stdin); freopen(data".out", "w", stdout);
#define pb push_back
#define all(data) data.begin(), data.end()
#define endl '\n'
#define ll long long
//#define int long long
#define pii pair < int, int >

using namespace std;

const int N = 2e5 + 5;

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

long long get(int dv) {
    long long res1 = 0, res2 = 0, need = 0;
    for(int i = 1; i <= k; i++) {
        if(((x[i] + dv - 1) / dv + (y[i] + dv - 1) / dv) % 2 == 0) {
            res1++;
        } else {
            res2++;
        }
    }
    //cout << dv << " " << res1 + ((n / dv) * (n / dv)) / 2 * dv * dv - res2 << " " << res2 + ((n / dv) * (n / dv) + 1) / 2 * dv * dv - res1 << endl;
    return min(res1 + ((n / dv) * (n / dv)) / 2 * dv * dv - res2, res2 + ((n / dv) * (n / dv) + 1) / 2 * dv * dv - res1);
}

main() {
    //file("pieaters");
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    cin >> n >> k;
    for(int i = 1; i <= k; i++) {
        int xx, yy;
        cin >> x[i] >> y[i] >> xx >> yy;
    }
    long long ans = n * n * n;
    bool ok = 1;
    for(int i = 1; i < n; i++) {
        if(n % i == 0) {
            ans = min(ans, get(i));
            if(i > 1) ok = 0;
        }
    }
    if(ok) {
        int even = 0, odd = 0;
        for(int i = 1; i <= k; i++) {
            int xx, yy;
            //cin >> x[i] >> y[i] >> xx >> yy;
            if(x[i] % 2 == y[i] % 2) ++odd;
            else even++;
        }
        int ev = (n * n + 1) / 2, od = (n * n) / 2;
        cout << min(ev - odd + even, od - even + odd);
        return 0;
    }
    cout << ans;
}






Compilation message

chessboard.cpp: In function 'long long int get(int)':
chessboard.cpp:22:35: warning: unused variable 'need' [-Wunused-variable]
   22 |     long long res1 = 0, res2 = 0, need = 0;
      |                                   ^~~~
chessboard.cpp: At global scope:
chessboard.cpp:34:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
   34 | main() {
      | ^~~~
chessboard.cpp: In function 'int main()':
chessboard.cpp:55:17: warning: unused variable 'xx' [-Wunused-variable]
   55 |             int xx, yy;
      |                 ^~
chessboard.cpp:55:21: warning: unused variable 'yy' [-Wunused-variable]
   55 |             int xx, yy;
      |                     ^~
# Verdict Execution time Memory Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 0 ms 204 KB Output is correct
5 Correct 0 ms 204 KB Output is correct
6 Correct 0 ms 204 KB Output is correct
7 Correct 0 ms 204 KB Output is correct
8 Correct 0 ms 204 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 20 ms 716 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 332 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
3 Correct 0 ms 204 KB Output is correct
4 Correct 1 ms 332 KB Output is correct
5 Correct 1 ms 332 KB Output is correct
6 Correct 1 ms 204 KB Output is correct
7 Correct 1 ms 332 KB Output is correct
8 Correct 1 ms 332 KB Output is correct
9 Correct 1 ms 332 KB Output is correct
10 Correct 0 ms 204 KB Output is correct
11 Correct 1 ms 332 KB Output is correct
12 Correct 1 ms 332 KB Output is correct
13 Correct 1 ms 332 KB Output is correct
14 Correct 1 ms 332 KB Output is correct
15 Correct 1 ms 332 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 332 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
3 Correct 0 ms 204 KB Output is correct
4 Correct 1 ms 332 KB Output is correct
5 Correct 1 ms 332 KB Output is correct
6 Correct 1 ms 204 KB Output is correct
7 Correct 1 ms 332 KB Output is correct
8 Correct 1 ms 332 KB Output is correct
9 Correct 1 ms 332 KB Output is correct
10 Correct 0 ms 204 KB Output is correct
11 Correct 1 ms 332 KB Output is correct
12 Correct 1 ms 332 KB Output is correct
13 Correct 1 ms 332 KB Output is correct
14 Correct 1 ms 332 KB Output is correct
15 Correct 1 ms 332 KB Output is correct
16 Correct 9 ms 496 KB Output is correct
17 Correct 25 ms 872 KB Output is correct
18 Correct 29 ms 1096 KB Output is correct
19 Correct 56 ms 972 KB Output is correct
20 Correct 77 ms 1048 KB Output is correct
21 Correct 20 ms 924 KB Output is correct
22 Correct 1 ms 332 KB Output is correct
23 Correct 15 ms 596 KB Output is correct
24 Correct 24 ms 932 KB Output is correct
25 Correct 3 ms 332 KB Output is correct
26 Correct 23 ms 704 KB Output is correct
27 Correct 23 ms 732 KB Output is correct
28 Correct 29 ms 1056 KB Output is correct
29 Correct 10 ms 588 KB Output is correct
30 Correct 1 ms 332 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 20 ms 716 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 0 ms 204 KB Output is correct
5 Correct 0 ms 204 KB Output is correct
6 Correct 0 ms 204 KB Output is correct
7 Correct 0 ms 204 KB Output is correct
8 Correct 0 ms 204 KB Output is correct
9 Incorrect 20 ms 716 KB Output isn't correct
10 Halted 0 ms 0 KB -