답안 #892964

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
892964 2023-12-26T09:15:48 Z vjudge1 Chessboard (IZhO18_chessboard) C++17
47 / 100
212 ms 262144 KB
// 以上帝的名义
// 候选硕士
#include <bits/stdc++.h>

#ifdef local
#include "algo/debug.h"
#else
#define dbg(x...) 0
#endif

using namespace std ;
using ll = long long ;

bool isPrime(int x) {
    if (x < 2) return 0 ;
    for (int i = 2 ; i * i <= x ; i++) {
        if (x  % i == 0) {
            return 0 ;
        }
    }
    return 1 ;
}

int32_t main() {
    cin.tie(0)->sync_with_stdio(false) ;
    ll n, k ; cin >> n >> k ;
    if (isPrime(n)) {
        vector<vector<ll>> row(n + 1, vector<ll>(2, 0)) ;
        auto black = row , white = row ;
        while (k--) {
            int x1 , y1 , x2,  y2 ;cin >> x1 >> y1 >> x2 >> y2 ;
            row[x1][y1 % 2]++ ;
            black[x1][y1 % 2]++ ;
        }
        ll ret = 0 , sum = 0 ;
        for (int i = 1 ; i <= n ; i++) {
            if (i & 1) {
                ll len = (n + 1) / 2 ;
                ll cur = len - black[i][i % 2] + black[i][!(i % 2)] ;
                sum += cur ;
            } else {
                ll len = (n / 2) ;
                ll cur = len - black[i][i % 2] + black[i][!(i % 2)] ;
                sum += cur ;

            }
        }
        ret = sum ; sum = 0 ;
        for (int i = 1 ; i <= n ; i++) {
            if (i & 1) {
                ll len = (n) / 2 ;
                ll cur = len - black[i][!(i % 2)] + black[i][(i % 2)] ;
                sum += cur ;
            } else {
                ll len = ((n + 1) / 2) ;
                ll cur = len - black[i][!(i % 2)] + black[i][(i % 2)] ;
                sum += cur ;

            }
        }
        ret = min(ret, sum) ;
        cout << ret ;
        return 0 ;
    }
    vector<vector<int>> a(n + 2, vector<int>(n + 2, 0)) ;
    auto b = a ;
    for (int i = 0 ; i < k ; i++) {
        int x1 , y1 , x2 , y2 ; cin >> x1 >> y1 >> x2 >> y2 ;
        a[x1][y1]++ , a[x1][y2 + 1]-- ;
        a[x2 + 1][y1]-- , a[x2 + 1][y2 + 1]++ ;
    }
    for (int i = 1 ; i <= n ; i++) {
        for (int j = 1 ; j <= n ; j++) {
            a[i][j] += a[i - 1][j] ;
            a[i][j] += a[i][j - 1] ;
            a[i][j] -= a[i - 1][j - 1] ;
            a[i][j] = bool (a[i][j]) ;
            b[i][j] = b[i - 1][j] + b[i][j - 1] + a[i][j] - b[i - 1][j - 1] ;
        }
    }
    vector<int> d;
    for (int i = 1 ; i * i <= n ; i++) {
        if (n % i) continue ;
        d.push_back(i) ;
        if (n / i != i) d.push_back(n / i) ;
    }
    auto calc = [&](int len) -> int {
        int N = n / len ;
        vector<vector<vector<int>>> c(len + 3, vector<vector<int>>(len + 3, vector<int>(2 ,0))) ;
        for (int i = 1 ; i <= n ; i++) {
            for (int j = 1 ; j <= n ; j++) {
                c[(i - 1) / N][(j - 1) / N][a[i][j]]++ ;
            }
        }
        ll cur = 0 , ret = 0 ;
        for (int i = 0 ; i < len ; i++) {
            for (int j = 0 ; j < len ; j++) {
//                dbg(i, j, c[i][j][0], c[i][j][1]) ;
                if ((i % 2) != (j % 2)) {
                    ll sum = N * N - c[i][j][1] ;
                    cur += sum ;
                } else {
                    ll sum = N * N - c[i][j][0] ;
                    cur += sum ;
                }
            }
        }
        ret = cur , cur = 0 ;
        for (int i = 0 ; i < len ; i++) {
            for (int j = 0 ; j < len ; j++) {
                if ((i % 2) == (j % 2)) {
                    ll sum = N * N - c[i][j][1] ;
                    cur += sum ;
                } else {
                    ll sum = N * N - c[i][j][0] ;
                    cur += sum ;
                }
            }
        }
        ret = min(ret, cur) ;
        return ret ;
    };
    sort(d.begin(), d.end()) ;
    int ret = INT_MAX ;
    for (int i : d) {
        if (i > 1) {
            dbg(i, calc(i)) ;
            ret = min(ret, calc(i)) ;
        }
    }
    cout << ret ;
    return 0 ;
}

// 希望白银

Compilation message

chessboard.cpp: In function 'int32_t main()':
chessboard.cpp:8:19: warning: statement has no effect [-Wunused-value]
    8 | #define dbg(x...) 0
      |                   ^
chessboard.cpp:127:13: note: in expansion of macro 'dbg'
  127 |             dbg(i, calc(i)) ;
      |             ^~~
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 2 ms 1116 KB Output is correct
3 Correct 1 ms 1116 KB Output is correct
4 Correct 1 ms 856 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 1 ms 860 KB Output is correct
7 Correct 1 ms 860 KB Output is correct
8 Correct 1 ms 860 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 26 ms 10588 KB Output is correct
2 Correct 7 ms 2652 KB Output is correct
3 Correct 23 ms 13924 KB Output is correct
4 Correct 11 ms 1628 KB Output is correct
5 Correct 23 ms 10844 KB Output is correct
6 Correct 16 ms 9052 KB Output is correct
7 Correct 5 ms 4188 KB Output is correct
8 Correct 16 ms 9300 KB Output is correct
9 Correct 27 ms 7512 KB Output is correct
10 Correct 19 ms 7772 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 860 KB Output is correct
2 Correct 1 ms 604 KB Output is correct
3 Correct 1 ms 860 KB Output is correct
4 Correct 1 ms 860 KB Output is correct
5 Correct 1 ms 856 KB Output is correct
6 Correct 1 ms 1112 KB Output is correct
7 Correct 1 ms 860 KB Output is correct
8 Correct 1 ms 604 KB Output is correct
9 Correct 1 ms 1052 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 1 ms 604 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 1 ms 600 KB Output is correct
14 Correct 1 ms 860 KB Output is correct
15 Correct 1 ms 604 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 860 KB Output is correct
2 Correct 1 ms 604 KB Output is correct
3 Correct 1 ms 860 KB Output is correct
4 Correct 1 ms 860 KB Output is correct
5 Correct 1 ms 856 KB Output is correct
6 Correct 1 ms 1112 KB Output is correct
7 Correct 1 ms 860 KB Output is correct
8 Correct 1 ms 604 KB Output is correct
9 Correct 1 ms 1052 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 1 ms 604 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 1 ms 600 KB Output is correct
14 Correct 1 ms 860 KB Output is correct
15 Correct 1 ms 604 KB Output is correct
16 Correct 73 ms 57512 KB Output is correct
17 Correct 16 ms 600 KB Output is correct
18 Correct 95 ms 62828 KB Output is correct
19 Correct 212 ms 58508 KB Output is correct
20 Correct 205 ms 58444 KB Output is correct
21 Correct 16 ms 600 KB Output is correct
22 Correct 142 ms 63744 KB Output is correct
23 Correct 103 ms 59620 KB Output is correct
24 Correct 89 ms 62932 KB Output is correct
25 Correct 91 ms 59732 KB Output is correct
26 Correct 78 ms 57996 KB Output is correct
27 Correct 101 ms 58964 KB Output is correct
28 Correct 91 ms 58192 KB Output is correct
29 Correct 10 ms 600 KB Output is correct
30 Correct 77 ms 61268 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 26 ms 10588 KB Output is correct
2 Correct 7 ms 2652 KB Output is correct
3 Correct 23 ms 13924 KB Output is correct
4 Correct 11 ms 1628 KB Output is correct
5 Correct 23 ms 10844 KB Output is correct
6 Correct 16 ms 9052 KB Output is correct
7 Correct 5 ms 4188 KB Output is correct
8 Correct 16 ms 9300 KB Output is correct
9 Correct 27 ms 7512 KB Output is correct
10 Correct 19 ms 7772 KB Output is correct
11 Correct 1 ms 860 KB Output is correct
12 Correct 1 ms 604 KB Output is correct
13 Correct 1 ms 860 KB Output is correct
14 Correct 1 ms 860 KB Output is correct
15 Correct 1 ms 856 KB Output is correct
16 Correct 1 ms 1112 KB Output is correct
17 Correct 1 ms 860 KB Output is correct
18 Correct 1 ms 604 KB Output is correct
19 Correct 1 ms 1052 KB Output is correct
20 Correct 0 ms 348 KB Output is correct
21 Correct 1 ms 604 KB Output is correct
22 Correct 0 ms 348 KB Output is correct
23 Correct 1 ms 600 KB Output is correct
24 Correct 1 ms 860 KB Output is correct
25 Correct 1 ms 604 KB Output is correct
26 Correct 73 ms 57512 KB Output is correct
27 Correct 16 ms 600 KB Output is correct
28 Correct 95 ms 62828 KB Output is correct
29 Correct 212 ms 58508 KB Output is correct
30 Correct 205 ms 58444 KB Output is correct
31 Correct 16 ms 600 KB Output is correct
32 Correct 142 ms 63744 KB Output is correct
33 Correct 103 ms 59620 KB Output is correct
34 Correct 89 ms 62932 KB Output is correct
35 Correct 91 ms 59732 KB Output is correct
36 Correct 78 ms 57996 KB Output is correct
37 Correct 101 ms 58964 KB Output is correct
38 Correct 91 ms 58192 KB Output is correct
39 Correct 10 ms 600 KB Output is correct
40 Correct 77 ms 61268 KB Output is correct
41 Runtime error 98 ms 262144 KB Execution killed with signal 9
42 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 2 ms 1116 KB Output is correct
3 Correct 1 ms 1116 KB Output is correct
4 Correct 1 ms 856 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 1 ms 860 KB Output is correct
7 Correct 1 ms 860 KB Output is correct
8 Correct 1 ms 860 KB Output is correct
9 Correct 26 ms 10588 KB Output is correct
10 Correct 7 ms 2652 KB Output is correct
11 Correct 23 ms 13924 KB Output is correct
12 Correct 11 ms 1628 KB Output is correct
13 Correct 23 ms 10844 KB Output is correct
14 Correct 16 ms 9052 KB Output is correct
15 Correct 5 ms 4188 KB Output is correct
16 Correct 16 ms 9300 KB Output is correct
17 Correct 27 ms 7512 KB Output is correct
18 Correct 19 ms 7772 KB Output is correct
19 Correct 1 ms 860 KB Output is correct
20 Correct 1 ms 604 KB Output is correct
21 Correct 1 ms 860 KB Output is correct
22 Correct 1 ms 860 KB Output is correct
23 Correct 1 ms 856 KB Output is correct
24 Correct 1 ms 1112 KB Output is correct
25 Correct 1 ms 860 KB Output is correct
26 Correct 1 ms 604 KB Output is correct
27 Correct 1 ms 1052 KB Output is correct
28 Correct 0 ms 348 KB Output is correct
29 Correct 1 ms 604 KB Output is correct
30 Correct 0 ms 348 KB Output is correct
31 Correct 1 ms 600 KB Output is correct
32 Correct 1 ms 860 KB Output is correct
33 Correct 1 ms 604 KB Output is correct
34 Correct 73 ms 57512 KB Output is correct
35 Correct 16 ms 600 KB Output is correct
36 Correct 95 ms 62828 KB Output is correct
37 Correct 212 ms 58508 KB Output is correct
38 Correct 205 ms 58444 KB Output is correct
39 Correct 16 ms 600 KB Output is correct
40 Correct 142 ms 63744 KB Output is correct
41 Correct 103 ms 59620 KB Output is correct
42 Correct 89 ms 62932 KB Output is correct
43 Correct 91 ms 59732 KB Output is correct
44 Correct 78 ms 57996 KB Output is correct
45 Correct 101 ms 58964 KB Output is correct
46 Correct 91 ms 58192 KB Output is correct
47 Correct 10 ms 600 KB Output is correct
48 Correct 77 ms 61268 KB Output is correct
49 Runtime error 98 ms 262144 KB Execution killed with signal 9
50 Halted 0 ms 0 KB -