답안 #496379

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
496379 2021-12-21T06:39:09 Z kingline Chessboard (IZhO18_chessboard) C++17
8 / 100
22 ms 696 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(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);
        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() {
      | ^~~~
# 결과 실행 시간 메모리 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 1 ms 204 KB Output is correct
7 Correct 1 ms 204 KB Output is correct
8 Correct 1 ms 204 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Incorrect 22 ms 696 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 208 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
3 Correct 1 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 0 ms 332 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 Incorrect 0 ms 204 KB Output isn't correct
11 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 208 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
3 Correct 1 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 0 ms 332 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 Incorrect 0 ms 204 KB Output isn't correct
11 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 22 ms 696 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 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 1 ms 204 KB Output is correct
7 Correct 1 ms 204 KB Output is correct
8 Correct 1 ms 204 KB Output is correct
9 Incorrect 22 ms 696 KB Output isn't correct
10 Halted 0 ms 0 KB -