Submission #892998

# Submission time Handle Problem Language Result Execution time Memory
892998 2023-12-26T09:51:26 Z vjudge1 Chessboard (IZhO18_chessboard) C++17
70 / 100
174 ms 11356 KB
// 以上帝的名义
// 候选硕士
#include <bits/stdc++.h>

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

using namespace std ;
using ll = long long ;

#define int ll

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(del + 1, 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:48:47: warning: unused variable 'x2' [-Wunused-variable]
   48 |             int x1 = a[i].x1 , y1 = a[i].y1 , x2 = a[i].x2, y2 = a[i].y2 ;
      |                                               ^~
chessboard.cpp:48:61: warning: unused variable 'y2' [-Wunused-variable]
   48 |             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:51:9: note: in expansion of macro 'dbg'
   51 |         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:86:9: note: in expansion of macro 'dbg'
   86 |         dbg(i, calc(i)) ;
      |         ^~~
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 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 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 1 ms 348 KB Output is correct
8 Correct 0 ms 344 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 19 ms 5724 KB Output is correct
2 Correct 5 ms 1628 KB Output is correct
3 Correct 14 ms 6236 KB Output is correct
4 Correct 11 ms 1884 KB Output is correct
5 Correct 16 ms 5212 KB Output is correct
6 Correct 11 ms 4124 KB Output is correct
7 Correct 3 ms 1884 KB Output is correct
8 Correct 11 ms 4188 KB Output is correct
9 Correct 29 ms 4832 KB Output is correct
10 Correct 15 ms 3932 KB Output is correct
# 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 1 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 1 ms 348 KB Output is correct
8 Correct 1 ms 348 KB Output is correct
9 Correct 1 ms 344 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 1 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 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 1 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 1 ms 348 KB Output is correct
8 Correct 1 ms 348 KB Output is correct
9 Correct 1 ms 344 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 1 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 7 ms 1444 KB Output is correct
17 Correct 17 ms 2908 KB Output is correct
18 Correct 23 ms 3568 KB Output is correct
19 Correct 40 ms 3160 KB Output is correct
20 Correct 45 ms 3420 KB Output is correct
21 Correct 17 ms 2904 KB Output is correct
22 Correct 1 ms 348 KB Output is correct
23 Correct 12 ms 1676 KB Output is correct
24 Correct 22 ms 3160 KB Output is correct
25 Correct 4 ms 600 KB Output is correct
26 Correct 13 ms 2140 KB Output is correct
27 Correct 17 ms 2392 KB Output is correct
28 Correct 22 ms 3420 KB Output is correct
29 Correct 7 ms 1508 KB Output is correct
30 Correct 1 ms 344 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 19 ms 5724 KB Output is correct
2 Correct 5 ms 1628 KB Output is correct
3 Correct 14 ms 6236 KB Output is correct
4 Correct 11 ms 1884 KB Output is correct
5 Correct 16 ms 5212 KB Output is correct
6 Correct 11 ms 4124 KB Output is correct
7 Correct 3 ms 1884 KB Output is correct
8 Correct 11 ms 4188 KB Output is correct
9 Correct 29 ms 4832 KB Output is correct
10 Correct 15 ms 3932 KB Output is correct
11 Correct 0 ms 348 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 0 ms 348 KB Output is correct
17 Correct 1 ms 348 KB Output is correct
18 Correct 1 ms 348 KB Output is correct
19 Correct 1 ms 344 KB Output is correct
20 Correct 0 ms 348 KB Output is correct
21 Correct 0 ms 348 KB Output is correct
22 Correct 0 ms 348 KB Output is correct
23 Correct 1 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 7 ms 1444 KB Output is correct
27 Correct 17 ms 2908 KB Output is correct
28 Correct 23 ms 3568 KB Output is correct
29 Correct 40 ms 3160 KB Output is correct
30 Correct 45 ms 3420 KB Output is correct
31 Correct 17 ms 2904 KB Output is correct
32 Correct 1 ms 348 KB Output is correct
33 Correct 12 ms 1676 KB Output is correct
34 Correct 22 ms 3160 KB Output is correct
35 Correct 4 ms 600 KB Output is correct
36 Correct 13 ms 2140 KB Output is correct
37 Correct 17 ms 2392 KB Output is correct
38 Correct 22 ms 3420 KB Output is correct
39 Correct 7 ms 1508 KB Output is correct
40 Correct 1 ms 344 KB Output is correct
41 Correct 49 ms 8280 KB Output is correct
42 Correct 33 ms 11076 KB Output is correct
43 Correct 38 ms 10320 KB Output is correct
44 Correct 32 ms 10832 KB Output is correct
45 Correct 29 ms 11356 KB Output is correct
46 Correct 54 ms 10836 KB Output is correct
47 Correct 30 ms 10584 KB Output is correct
48 Correct 34 ms 10588 KB Output is correct
49 Correct 29 ms 10320 KB Output is correct
50 Correct 159 ms 9808 KB Output is correct
51 Correct 168 ms 10328 KB Output is correct
52 Correct 156 ms 9812 KB Output is correct
53 Correct 167 ms 10068 KB Output is correct
54 Correct 155 ms 9892 KB Output is correct
55 Correct 174 ms 10316 KB Output is correct
56 Correct 151 ms 9556 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 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 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 1 ms 348 KB Output is correct
8 Correct 0 ms 344 KB Output is correct
9 Correct 19 ms 5724 KB Output is correct
10 Correct 5 ms 1628 KB Output is correct
11 Correct 14 ms 6236 KB Output is correct
12 Correct 11 ms 1884 KB Output is correct
13 Correct 16 ms 5212 KB Output is correct
14 Correct 11 ms 4124 KB Output is correct
15 Correct 3 ms 1884 KB Output is correct
16 Correct 11 ms 4188 KB Output is correct
17 Correct 29 ms 4832 KB Output is correct
18 Correct 15 ms 3932 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 348 KB Output is correct
22 Correct 1 ms 348 KB Output is correct
23 Correct 0 ms 348 KB Output is correct
24 Correct 0 ms 348 KB Output is correct
25 Correct 1 ms 348 KB Output is correct
26 Correct 1 ms 348 KB Output is correct
27 Correct 1 ms 344 KB Output is correct
28 Correct 0 ms 348 KB Output is correct
29 Correct 0 ms 348 KB Output is correct
30 Correct 0 ms 348 KB Output is correct
31 Correct 1 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 7 ms 1444 KB Output is correct
35 Correct 17 ms 2908 KB Output is correct
36 Correct 23 ms 3568 KB Output is correct
37 Correct 40 ms 3160 KB Output is correct
38 Correct 45 ms 3420 KB Output is correct
39 Correct 17 ms 2904 KB Output is correct
40 Correct 1 ms 348 KB Output is correct
41 Correct 12 ms 1676 KB Output is correct
42 Correct 22 ms 3160 KB Output is correct
43 Correct 4 ms 600 KB Output is correct
44 Correct 13 ms 2140 KB Output is correct
45 Correct 17 ms 2392 KB Output is correct
46 Correct 22 ms 3420 KB Output is correct
47 Correct 7 ms 1508 KB Output is correct
48 Correct 1 ms 344 KB Output is correct
49 Correct 49 ms 8280 KB Output is correct
50 Correct 33 ms 11076 KB Output is correct
51 Correct 38 ms 10320 KB Output is correct
52 Correct 32 ms 10832 KB Output is correct
53 Correct 29 ms 11356 KB Output is correct
54 Correct 54 ms 10836 KB Output is correct
55 Correct 30 ms 10584 KB Output is correct
56 Correct 34 ms 10588 KB Output is correct
57 Correct 29 ms 10320 KB Output is correct
58 Correct 159 ms 9808 KB Output is correct
59 Correct 168 ms 10328 KB Output is correct
60 Correct 156 ms 9812 KB Output is correct
61 Correct 167 ms 10068 KB Output is correct
62 Correct 155 ms 9892 KB Output is correct
63 Correct 174 ms 10316 KB Output is correct
64 Correct 151 ms 9556 KB Output is correct
65 Correct 0 ms 348 KB Output is correct
66 Incorrect 0 ms 348 KB Output isn't correct
67 Halted 0 ms 0 KB -