답안 #496383

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
496383 2021-12-21T06:42:02 Z kingline Chessboard (IZhO18_chessboard) C++17
70 / 100
220 ms 4248 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;
    }
    bool ok = 1;
    for(int i = 2; i <= sqrt(n); i++) {
        if(n % i ==0 ) ok =0 ;
    }
    if(ok) {
        int even = 0, odd = 0;
        for(int i = 1; i <= k; i++) {
            //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;
    }
    long long ans = n * n * n;
    for(int i = 1; i < n; i++) {
        if(n % i == 0) {
            ans = min(ans, get(i));
        }
    }
    cout << ans;
}






Compilation message

chessboard.cpp: In function 'long long int get(long long 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 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
# 결과 실행 시간 메모리 Grader output
1 Correct 26 ms 1296 KB Output is correct
2 Correct 8 ms 824 KB Output is correct
3 Correct 15 ms 1844 KB Output is correct
4 Correct 14 ms 1764 KB Output is correct
5 Correct 16 ms 2360 KB Output is correct
6 Correct 12 ms 1660 KB Output is correct
7 Correct 4 ms 580 KB Output is correct
8 Correct 11 ms 1588 KB Output is correct
9 Correct 44 ms 3704 KB Output is correct
10 Correct 15 ms 2208 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 204 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 0 ms 332 KB Output is correct
7 Correct 2 ms 332 KB Output is correct
8 Correct 1 ms 332 KB Output is correct
9 Correct 0 ms 332 KB Output is correct
10 Correct 1 ms 204 KB Output is correct
11 Correct 0 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
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 204 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 0 ms 332 KB Output is correct
7 Correct 2 ms 332 KB Output is correct
8 Correct 1 ms 332 KB Output is correct
9 Correct 0 ms 332 KB Output is correct
10 Correct 1 ms 204 KB Output is correct
11 Correct 0 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 7 ms 716 KB Output is correct
17 Correct 21 ms 1612 KB Output is correct
18 Correct 31 ms 1756 KB Output is correct
19 Correct 58 ms 1612 KB Output is correct
20 Correct 60 ms 1844 KB Output is correct
21 Correct 20 ms 1528 KB Output is correct
22 Correct 1 ms 332 KB Output is correct
23 Correct 15 ms 972 KB Output is correct
24 Correct 25 ms 1676 KB Output is correct
25 Correct 3 ms 332 KB Output is correct
26 Correct 15 ms 1112 KB Output is correct
27 Correct 20 ms 1272 KB Output is correct
28 Correct 25 ms 1760 KB Output is correct
29 Correct 8 ms 812 KB Output is correct
30 Correct 1 ms 332 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 26 ms 1296 KB Output is correct
2 Correct 8 ms 824 KB Output is correct
3 Correct 15 ms 1844 KB Output is correct
4 Correct 14 ms 1764 KB Output is correct
5 Correct 16 ms 2360 KB Output is correct
6 Correct 12 ms 1660 KB Output is correct
7 Correct 4 ms 580 KB Output is correct
8 Correct 11 ms 1588 KB Output is correct
9 Correct 44 ms 3704 KB Output is correct
10 Correct 15 ms 2208 KB Output is correct
11 Correct 0 ms 204 KB Output is correct
12 Correct 0 ms 204 KB Output is correct
13 Correct 0 ms 204 KB Output is correct
14 Correct 1 ms 332 KB Output is correct
15 Correct 1 ms 332 KB Output is correct
16 Correct 0 ms 332 KB Output is correct
17 Correct 2 ms 332 KB Output is correct
18 Correct 1 ms 332 KB Output is correct
19 Correct 0 ms 332 KB Output is correct
20 Correct 1 ms 204 KB Output is correct
21 Correct 0 ms 332 KB Output is correct
22 Correct 1 ms 332 KB Output is correct
23 Correct 1 ms 332 KB Output is correct
24 Correct 1 ms 332 KB Output is correct
25 Correct 1 ms 332 KB Output is correct
26 Correct 7 ms 716 KB Output is correct
27 Correct 21 ms 1612 KB Output is correct
28 Correct 31 ms 1756 KB Output is correct
29 Correct 58 ms 1612 KB Output is correct
30 Correct 60 ms 1844 KB Output is correct
31 Correct 20 ms 1528 KB Output is correct
32 Correct 1 ms 332 KB Output is correct
33 Correct 15 ms 972 KB Output is correct
34 Correct 25 ms 1676 KB Output is correct
35 Correct 3 ms 332 KB Output is correct
36 Correct 15 ms 1112 KB Output is correct
37 Correct 20 ms 1272 KB Output is correct
38 Correct 25 ms 1760 KB Output is correct
39 Correct 8 ms 812 KB Output is correct
40 Correct 1 ms 332 KB Output is correct
41 Correct 56 ms 3524 KB Output is correct
42 Correct 34 ms 4028 KB Output is correct
43 Correct 41 ms 3656 KB Output is correct
44 Correct 31 ms 3908 KB Output is correct
45 Correct 30 ms 4124 KB Output is correct
46 Correct 60 ms 3960 KB Output is correct
47 Correct 30 ms 3632 KB Output is correct
48 Correct 34 ms 3652 KB Output is correct
49 Correct 35 ms 3608 KB Output is correct
50 Correct 197 ms 3912 KB Output is correct
51 Correct 220 ms 4124 KB Output is correct
52 Correct 202 ms 3868 KB Output is correct
53 Correct 212 ms 4036 KB Output is correct
54 Correct 193 ms 3764 KB Output is correct
55 Correct 220 ms 4248 KB Output is correct
56 Correct 188 ms 3760 KB Output is correct
# 결과 실행 시간 메모리 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 Correct 26 ms 1296 KB Output is correct
10 Correct 8 ms 824 KB Output is correct
11 Correct 15 ms 1844 KB Output is correct
12 Correct 14 ms 1764 KB Output is correct
13 Correct 16 ms 2360 KB Output is correct
14 Correct 12 ms 1660 KB Output is correct
15 Correct 4 ms 580 KB Output is correct
16 Correct 11 ms 1588 KB Output is correct
17 Correct 44 ms 3704 KB Output is correct
18 Correct 15 ms 2208 KB Output is correct
19 Correct 0 ms 204 KB Output is correct
20 Correct 0 ms 204 KB Output is correct
21 Correct 0 ms 204 KB Output is correct
22 Correct 1 ms 332 KB Output is correct
23 Correct 1 ms 332 KB Output is correct
24 Correct 0 ms 332 KB Output is correct
25 Correct 2 ms 332 KB Output is correct
26 Correct 1 ms 332 KB Output is correct
27 Correct 0 ms 332 KB Output is correct
28 Correct 1 ms 204 KB Output is correct
29 Correct 0 ms 332 KB Output is correct
30 Correct 1 ms 332 KB Output is correct
31 Correct 1 ms 332 KB Output is correct
32 Correct 1 ms 332 KB Output is correct
33 Correct 1 ms 332 KB Output is correct
34 Correct 7 ms 716 KB Output is correct
35 Correct 21 ms 1612 KB Output is correct
36 Correct 31 ms 1756 KB Output is correct
37 Correct 58 ms 1612 KB Output is correct
38 Correct 60 ms 1844 KB Output is correct
39 Correct 20 ms 1528 KB Output is correct
40 Correct 1 ms 332 KB Output is correct
41 Correct 15 ms 972 KB Output is correct
42 Correct 25 ms 1676 KB Output is correct
43 Correct 3 ms 332 KB Output is correct
44 Correct 15 ms 1112 KB Output is correct
45 Correct 20 ms 1272 KB Output is correct
46 Correct 25 ms 1760 KB Output is correct
47 Correct 8 ms 812 KB Output is correct
48 Correct 1 ms 332 KB Output is correct
49 Correct 56 ms 3524 KB Output is correct
50 Correct 34 ms 4028 KB Output is correct
51 Correct 41 ms 3656 KB Output is correct
52 Correct 31 ms 3908 KB Output is correct
53 Correct 30 ms 4124 KB Output is correct
54 Correct 60 ms 3960 KB Output is correct
55 Correct 30 ms 3632 KB Output is correct
56 Correct 34 ms 3652 KB Output is correct
57 Correct 35 ms 3608 KB Output is correct
58 Correct 197 ms 3912 KB Output is correct
59 Correct 220 ms 4124 KB Output is correct
60 Correct 202 ms 3868 KB Output is correct
61 Correct 212 ms 4036 KB Output is correct
62 Correct 193 ms 3764 KB Output is correct
63 Correct 220 ms 4248 KB Output is correct
64 Correct 188 ms 3760 KB Output is correct
65 Correct 0 ms 312 KB Output is correct
66 Incorrect 0 ms 204 KB Output isn't correct
67 Halted 0 ms 0 KB -