Submission #892962

# Submission time Handle Problem Language Result Execution time Memory
892962 2023-12-26T09:13:22 Z vjudge1 Chessboard (IZhO18_chessboard) C++17
39 / 100
226 ms 63572 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<int>> row(n + 1, vector<int>(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]++ ;
        }
        int ret = 0 , sum = 0 ;
        for (int i = 1 ; i <= n ; i++) {
            if (i & 1) {
                int len = (n + 1) / 2 ;
                int cur = len - black[i][i % 2] + black[i][!(i % 2)] ;
                sum += cur ;
            } else {
                int len = (n / 2) ;
                int 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) {
                int len = (n) / 2 ;
                int cur = len - black[i][!(i % 2)] + black[i][(i % 2)] ;
                sum += cur ;
            } else {
                int len = ((n + 1) / 2) ;
                int 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)) ;
      |             ^~~
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 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 860 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 2 ms 860 KB Output is correct
7 Correct 1 ms 860 KB Output is correct
8 Correct 1 ms 860 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 41 ms 11936 KB Output is correct
2 Correct 10 ms 2908 KB Output is correct
3 Incorrect 28 ms 15048 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 860 KB Output is correct
2 Correct 1 ms 604 KB Output is correct
3 Correct 1 ms 856 KB Output is correct
4 Correct 1 ms 860 KB Output is correct
5 Correct 1 ms 860 KB Output is correct
6 Correct 1 ms 860 KB Output is correct
7 Correct 1 ms 856 KB Output is correct
8 Correct 1 ms 604 KB Output is correct
9 Correct 1 ms 860 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 1 ms 604 KB Output is correct
12 Correct 1 ms 348 KB Output is correct
13 Correct 1 ms 604 KB Output is correct
14 Correct 1 ms 860 KB Output is correct
15 Correct 1 ms 604 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 860 KB Output is correct
2 Correct 1 ms 604 KB Output is correct
3 Correct 1 ms 856 KB Output is correct
4 Correct 1 ms 860 KB Output is correct
5 Correct 1 ms 860 KB Output is correct
6 Correct 1 ms 860 KB Output is correct
7 Correct 1 ms 856 KB Output is correct
8 Correct 1 ms 604 KB Output is correct
9 Correct 1 ms 860 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 1 ms 604 KB Output is correct
12 Correct 1 ms 348 KB Output is correct
13 Correct 1 ms 604 KB Output is correct
14 Correct 1 ms 860 KB Output is correct
15 Correct 1 ms 604 KB Output is correct
16 Correct 77 ms 57564 KB Output is correct
17 Correct 26 ms 600 KB Output is correct
18 Correct 98 ms 62824 KB Output is correct
19 Correct 220 ms 58588 KB Output is correct
20 Correct 226 ms 58424 KB Output is correct
21 Correct 15 ms 600 KB Output is correct
22 Correct 152 ms 63572 KB Output is correct
23 Correct 111 ms 59876 KB Output is correct
24 Correct 99 ms 62820 KB Output is correct
25 Correct 97 ms 59732 KB Output is correct
26 Correct 86 ms 58044 KB Output is correct
27 Correct 126 ms 58964 KB Output is correct
28 Correct 99 ms 58408 KB Output is correct
29 Correct 7 ms 604 KB Output is correct
30 Correct 82 ms 61112 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 41 ms 11936 KB Output is correct
2 Correct 10 ms 2908 KB Output is correct
3 Incorrect 28 ms 15048 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 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 860 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 2 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 41 ms 11936 KB Output is correct
10 Correct 10 ms 2908 KB Output is correct
11 Incorrect 28 ms 15048 KB Output isn't correct
12 Halted 0 ms 0 KB -