Submission #892993

# Submission time Handle Problem Language Result Execution time Memory
892993 2023-12-26T09:46:51 Z vjudge1 Chessboard (IZhO18_chessboard) C++17
47 / 100
132 ms 9240 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 ;
    struct rect {
        int x1, y1, x2, y2;
        void read() {
            cin >> x1 >> y1 >> x2 >> y2 ;
            x1--, y1-- , x2-- , y2-- ;
        }
    };
    vector<rect> a(k) ;
    for (int i = 0 ; i < k ; i++) a[i].read() ;
    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 = [&](ll del) -> ll{
        vector<vector<ll>> cnt(n, vector<ll>(2, 0)) ;
        int block = n / del ;
        for (int i = 0 ; i < k ; i++) {
            int x1 = a[i].x1 , y1 = a[i].y1 , x2 = a[i].x2, y2 = a[i].y2 ;
            cnt[x1 / block][(y1 / block) % 2]++;
        }
        dbg(cnt) ;
        ll ret = 0 , sum = 0 ;
        for (int i = 0 ; i < del ; i++) {
//            for (int j = 0 ; j < del ; j++) {
                if (i % 2 == 0) {
                    ll c = ((del + 1) / 2) * (block * block) ;
                    ll cur = c - cnt[i][0] + cnt[i][1] ;
                    sum += cur ;
                } else {
                    ll c = (del / 2) * (block * block) ;
                    ll cur = c - cnt[i][1] + cnt[i][0] ;
                    sum += cur ;
                }
//            }
        }
        ret = sum ;
        sum = 0 ;
        for (int i = 0 ; i < del ; i++) {
//            for (int j = 0 ; j < del ; j++) {
                if (i % 2 != 0) {
                    ll c = ((del + 1) / 2) * (block * block) ;
                    ll cur = c - cnt[i][0] + cnt[i][1] ;
                    sum += cur ;
                } else {
                    ll c = (del / 2) * (block * block) ;
                    ll cur = c - cnt[i][1] + cnt[i][0] ;
                    sum += cur ;
                }
//            }
        }
        ret = min(ret, sum) ;
        return ret ;
    };
    ll ret = LLONG_MAX ;
    for (int i : d) {
        dbg(i, calc(i)) ;
        if (i > 1)
            ret = min(ret, calc(i)) ;
    }
    cout << ret ;
    return 0 ;
}

// 希望白银

Compilation message

chessboard.cpp: In lambda function:
chessboard.cpp:46:47: warning: unused variable 'x2' [-Wunused-variable]
   46 |             int x1 = a[i].x1 , y1 = a[i].y1 , x2 = a[i].x2, y2 = a[i].y2 ;
      |                                               ^~
chessboard.cpp:46:61: warning: unused variable 'y2' [-Wunused-variable]
   46 |             int x1 = a[i].x1 , y1 = a[i].y1 , x2 = a[i].x2, y2 = a[i].y2 ;
      |                                                             ^~
chessboard.cpp:8:19: warning: statement has no effect [-Wunused-value]
    8 | #define dbg(x...) 0
      |                   ^
chessboard.cpp:49:9: note: in expansion of macro 'dbg'
   49 |         dbg(cnt) ;
      |         ^~~
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:84:9: note: in expansion of macro 'dbg'
   84 |         dbg(i, calc(i)) ;
      |         ^~~
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 344 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 1 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 18 ms 4688 KB Output is correct
2 Correct 5 ms 1372 KB Output is correct
3 Correct 14 ms 5468 KB Output is correct
4 Correct 11 ms 1116 KB Output is correct
5 Correct 16 ms 4184 KB Output is correct
6 Correct 11 ms 3416 KB Output is correct
7 Correct 4 ms 1628 KB Output is correct
8 Correct 11 ms 3676 KB Output is correct
9 Correct 26 ms 3412 KB Output is correct
10 Correct 14 ms 3164 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 0 ms 344 KB Output is correct
3 Correct 0 ms 344 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Correct 1 ms 464 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 1 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 344 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 1 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 0 ms 344 KB Output is correct
3 Correct 0 ms 344 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Correct 1 ms 464 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 1 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 344 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 1 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 6 ms 860 KB Output is correct
17 Correct 18 ms 1788 KB Output is correct
18 Correct 22 ms 1884 KB Output is correct
19 Correct 40 ms 1884 KB Output is correct
20 Correct 45 ms 1884 KB Output is correct
21 Correct 17 ms 1740 KB Output is correct
22 Correct 1 ms 348 KB Output is correct
23 Correct 12 ms 1372 KB Output is correct
24 Correct 20 ms 1880 KB Output is correct
25 Correct 3 ms 604 KB Output is correct
26 Correct 15 ms 1364 KB Output is correct
27 Correct 17 ms 1372 KB Output is correct
28 Correct 22 ms 1956 KB Output is correct
29 Correct 7 ms 860 KB Output is correct
30 Correct 1 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 18 ms 4688 KB Output is correct
2 Correct 5 ms 1372 KB Output is correct
3 Correct 14 ms 5468 KB Output is correct
4 Correct 11 ms 1116 KB Output is correct
5 Correct 16 ms 4184 KB Output is correct
6 Correct 11 ms 3416 KB Output is correct
7 Correct 4 ms 1628 KB Output is correct
8 Correct 11 ms 3676 KB Output is correct
9 Correct 26 ms 3412 KB Output is correct
10 Correct 14 ms 3164 KB Output is correct
11 Correct 1 ms 344 KB Output is correct
12 Correct 0 ms 344 KB Output is correct
13 Correct 0 ms 344 KB Output is correct
14 Correct 1 ms 348 KB Output is correct
15 Correct 1 ms 464 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 0 ms 348 KB Output is correct
18 Correct 1 ms 348 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 0 ms 348 KB Output is correct
21 Correct 0 ms 344 KB Output is correct
22 Correct 0 ms 348 KB Output is correct
23 Correct 0 ms 348 KB Output is correct
24 Correct 1 ms 348 KB Output is correct
25 Correct 0 ms 348 KB Output is correct
26 Correct 6 ms 860 KB Output is correct
27 Correct 18 ms 1788 KB Output is correct
28 Correct 22 ms 1884 KB Output is correct
29 Correct 40 ms 1884 KB Output is correct
30 Correct 45 ms 1884 KB Output is correct
31 Correct 17 ms 1740 KB Output is correct
32 Correct 1 ms 348 KB Output is correct
33 Correct 12 ms 1372 KB Output is correct
34 Correct 20 ms 1880 KB Output is correct
35 Correct 3 ms 604 KB Output is correct
36 Correct 15 ms 1364 KB Output is correct
37 Correct 17 ms 1372 KB Output is correct
38 Correct 22 ms 1956 KB Output is correct
39 Correct 7 ms 860 KB Output is correct
40 Correct 1 ms 348 KB Output is correct
41 Incorrect 132 ms 9240 KB Output isn't correct
42 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 344 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 1 ms 348 KB Output is correct
9 Correct 18 ms 4688 KB Output is correct
10 Correct 5 ms 1372 KB Output is correct
11 Correct 14 ms 5468 KB Output is correct
12 Correct 11 ms 1116 KB Output is correct
13 Correct 16 ms 4184 KB Output is correct
14 Correct 11 ms 3416 KB Output is correct
15 Correct 4 ms 1628 KB Output is correct
16 Correct 11 ms 3676 KB Output is correct
17 Correct 26 ms 3412 KB Output is correct
18 Correct 14 ms 3164 KB Output is correct
19 Correct 1 ms 344 KB Output is correct
20 Correct 0 ms 344 KB Output is correct
21 Correct 0 ms 344 KB Output is correct
22 Correct 1 ms 348 KB Output is correct
23 Correct 1 ms 464 KB Output is correct
24 Correct 0 ms 348 KB Output is correct
25 Correct 0 ms 348 KB Output is correct
26 Correct 1 ms 348 KB Output is correct
27 Correct 0 ms 348 KB Output is correct
28 Correct 0 ms 348 KB Output is correct
29 Correct 0 ms 344 KB Output is correct
30 Correct 0 ms 348 KB Output is correct
31 Correct 0 ms 348 KB Output is correct
32 Correct 1 ms 348 KB Output is correct
33 Correct 0 ms 348 KB Output is correct
34 Correct 6 ms 860 KB Output is correct
35 Correct 18 ms 1788 KB Output is correct
36 Correct 22 ms 1884 KB Output is correct
37 Correct 40 ms 1884 KB Output is correct
38 Correct 45 ms 1884 KB Output is correct
39 Correct 17 ms 1740 KB Output is correct
40 Correct 1 ms 348 KB Output is correct
41 Correct 12 ms 1372 KB Output is correct
42 Correct 20 ms 1880 KB Output is correct
43 Correct 3 ms 604 KB Output is correct
44 Correct 15 ms 1364 KB Output is correct
45 Correct 17 ms 1372 KB Output is correct
46 Correct 22 ms 1956 KB Output is correct
47 Correct 7 ms 860 KB Output is correct
48 Correct 1 ms 348 KB Output is correct
49 Incorrect 132 ms 9240 KB Output isn't correct
50 Halted 0 ms 0 KB -