답안 #879103

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
879103 2023-11-26T11:08:05 Z TheSahib Chessboard (IZhO18_chessboard) C++14
100 / 100
274 ms 8392 KB
#include <bits/stdc++.h>
 
#define ll long long
#define int ll
#define pii pair<int, int>
 
using namespace std;
 
const int MAX = 1e5 + 5;
const ll oo = 1e15;

ll n, k;

vector<array<int, 4>> v;

int f(int i, int d){
    if(i <= 0) return 0;
    int j = (i / d) * d;
    int a = ((j / d + 1) / 2) * d;
    if(!((j / d) & 1)) a += i - j;
    return a;
}
 
ll check(ll d){
    int pre[n + 1];
    pre[0] = 0;
    for (int i = 1; i <= n; i++)
    {
        pre[i] = pre[i - 1] + (f(i, d) - f(i - 1, d));
    }
    
    ll a = f(n, d) * pre[n] + (n - f(n, d)) * (n - pre[n]);
    for(auto& x:v){
        int c1 = f(x[1], d) - f(x[0] - 1, d);
        int c2 = x[1] - x[0] + 1 - c1;
        int p = pre[x[3]] - pre[x[2] - 1];
        a -= 1ll * p * c1;
        a += 1ll * (x[3] - x[2] + 1 - p) * c1;
        a -= 1ll * (x[3] - x[2] + 1 - p) * c2;
        a += 1ll * p * c2;  
    }
    return min(a, n * n - a);
}
 
void solve(){
    scanf("%lld%lld", &n, &k);
    for (int i = 0; i < k; i++)
    {
        int x1, y1, x2, y2; scanf("%lld%lld%lld%lld", &x1, &y1, &x2, &y2);
        v.push_back({x1, x2, y1, y2});
    }

    
    ll ans = oo;
    for (int i = 1; i * i <= n; i++)
    {
        if(n % i == 0){
            ans = min(ans, check(i));
            if(i != 1){
                ans = min(ans, check(n / i));
            }
        }
    }
    cout << ans << '\n';
}
/*
6 8
3 3 3 3
1 2 1 2
3 4 3 4
5 5 5 5
4 3 4 3
4 4 4 4
2 1 2 1
3 6 3 6
*/
 
signed main()
{
    solve();
}

Compilation message

chessboard.cpp: In function 'void solve()':
chessboard.cpp:46:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   46 |     scanf("%lld%lld", &n, &k);
      |     ~~~~~^~~~~~~~~~~~~~~~~~~~
chessboard.cpp:49:34: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   49 |         int x1, y1, x2, y2; scanf("%lld%lld%lld%lld", &x1, &y1, &x2, &y2);
      |                             ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 440 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 344 KB Output is correct
4 Correct 0 ms 500 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 432 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 1 ms 348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 19 ms 4264 KB Output is correct
2 Correct 5 ms 1748 KB Output is correct
3 Correct 13 ms 3380 KB Output is correct
4 Correct 13 ms 3320 KB Output is correct
5 Correct 16 ms 3788 KB Output is correct
6 Correct 15 ms 3536 KB Output is correct
7 Correct 3 ms 868 KB Output is correct
8 Correct 12 ms 3276 KB Output is correct
9 Correct 26 ms 7884 KB Output is correct
10 Correct 15 ms 3536 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 600 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 1 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 0 ms 348 KB Output is correct
10 Correct 1 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 0 ms 436 KB Output is correct
13 Correct 1 ms 344 KB Output is correct
14 Correct 1 ms 348 KB Output is correct
15 Correct 1 ms 348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 600 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 1 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 0 ms 348 KB Output is correct
10 Correct 1 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 0 ms 436 KB Output is correct
13 Correct 1 ms 344 KB Output is correct
14 Correct 1 ms 348 KB Output is correct
15 Correct 1 ms 348 KB Output is correct
16 Correct 7 ms 2256 KB Output is correct
17 Correct 21 ms 7804 KB Output is correct
18 Correct 28 ms 6072 KB Output is correct
19 Correct 44 ms 7976 KB Output is correct
20 Correct 49 ms 6604 KB Output is correct
21 Correct 21 ms 7372 KB Output is correct
22 Correct 1 ms 348 KB Output is correct
23 Correct 13 ms 3280 KB Output is correct
24 Correct 24 ms 7624 KB Output is correct
25 Correct 3 ms 984 KB Output is correct
26 Correct 15 ms 3308 KB Output is correct
27 Correct 24 ms 6348 KB Output is correct
28 Correct 26 ms 6720 KB Output is correct
29 Correct 9 ms 3024 KB Output is correct
30 Correct 1 ms 604 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 19 ms 4264 KB Output is correct
2 Correct 5 ms 1748 KB Output is correct
3 Correct 13 ms 3380 KB Output is correct
4 Correct 13 ms 3320 KB Output is correct
5 Correct 16 ms 3788 KB Output is correct
6 Correct 15 ms 3536 KB Output is correct
7 Correct 3 ms 868 KB Output is correct
8 Correct 12 ms 3276 KB Output is correct
9 Correct 26 ms 7884 KB Output is correct
10 Correct 15 ms 3536 KB Output is correct
11 Correct 0 ms 600 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 1 ms 348 KB Output is correct
16 Correct 1 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 1 ms 348 KB Output is correct
21 Correct 0 ms 348 KB Output is correct
22 Correct 0 ms 436 KB Output is correct
23 Correct 1 ms 344 KB Output is correct
24 Correct 1 ms 348 KB Output is correct
25 Correct 1 ms 348 KB Output is correct
26 Correct 7 ms 2256 KB Output is correct
27 Correct 21 ms 7804 KB Output is correct
28 Correct 28 ms 6072 KB Output is correct
29 Correct 44 ms 7976 KB Output is correct
30 Correct 49 ms 6604 KB Output is correct
31 Correct 21 ms 7372 KB Output is correct
32 Correct 1 ms 348 KB Output is correct
33 Correct 13 ms 3280 KB Output is correct
34 Correct 24 ms 7624 KB Output is correct
35 Correct 3 ms 984 KB Output is correct
36 Correct 15 ms 3308 KB Output is correct
37 Correct 24 ms 6348 KB Output is correct
38 Correct 26 ms 6720 KB Output is correct
39 Correct 9 ms 3024 KB Output is correct
40 Correct 1 ms 604 KB Output is correct
41 Correct 67 ms 8208 KB Output is correct
42 Correct 31 ms 7116 KB Output is correct
43 Correct 54 ms 7544 KB Output is correct
44 Correct 31 ms 8384 KB Output is correct
45 Correct 30 ms 8136 KB Output is correct
46 Correct 72 ms 6640 KB Output is correct
47 Correct 26 ms 6588 KB Output is correct
48 Correct 37 ms 6900 KB Output is correct
49 Correct 35 ms 7696 KB Output is correct
50 Correct 257 ms 6704 KB Output is correct
51 Correct 265 ms 7208 KB Output is correct
52 Correct 256 ms 7112 KB Output is correct
53 Correct 264 ms 7876 KB Output is correct
54 Correct 253 ms 6344 KB Output is correct
55 Correct 274 ms 6704 KB Output is correct
56 Correct 252 ms 7884 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 440 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 344 KB Output is correct
4 Correct 0 ms 500 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 432 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 1 ms 348 KB Output is correct
9 Correct 19 ms 4264 KB Output is correct
10 Correct 5 ms 1748 KB Output is correct
11 Correct 13 ms 3380 KB Output is correct
12 Correct 13 ms 3320 KB Output is correct
13 Correct 16 ms 3788 KB Output is correct
14 Correct 15 ms 3536 KB Output is correct
15 Correct 3 ms 868 KB Output is correct
16 Correct 12 ms 3276 KB Output is correct
17 Correct 26 ms 7884 KB Output is correct
18 Correct 15 ms 3536 KB Output is correct
19 Correct 0 ms 600 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 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 1 ms 348 KB Output is correct
27 Correct 0 ms 348 KB Output is correct
28 Correct 1 ms 348 KB Output is correct
29 Correct 0 ms 348 KB Output is correct
30 Correct 0 ms 436 KB Output is correct
31 Correct 1 ms 344 KB Output is correct
32 Correct 1 ms 348 KB Output is correct
33 Correct 1 ms 348 KB Output is correct
34 Correct 7 ms 2256 KB Output is correct
35 Correct 21 ms 7804 KB Output is correct
36 Correct 28 ms 6072 KB Output is correct
37 Correct 44 ms 7976 KB Output is correct
38 Correct 49 ms 6604 KB Output is correct
39 Correct 21 ms 7372 KB Output is correct
40 Correct 1 ms 348 KB Output is correct
41 Correct 13 ms 3280 KB Output is correct
42 Correct 24 ms 7624 KB Output is correct
43 Correct 3 ms 984 KB Output is correct
44 Correct 15 ms 3308 KB Output is correct
45 Correct 24 ms 6348 KB Output is correct
46 Correct 26 ms 6720 KB Output is correct
47 Correct 9 ms 3024 KB Output is correct
48 Correct 1 ms 604 KB Output is correct
49 Correct 67 ms 8208 KB Output is correct
50 Correct 31 ms 7116 KB Output is correct
51 Correct 54 ms 7544 KB Output is correct
52 Correct 31 ms 8384 KB Output is correct
53 Correct 30 ms 8136 KB Output is correct
54 Correct 72 ms 6640 KB Output is correct
55 Correct 26 ms 6588 KB Output is correct
56 Correct 37 ms 6900 KB Output is correct
57 Correct 35 ms 7696 KB Output is correct
58 Correct 257 ms 6704 KB Output is correct
59 Correct 265 ms 7208 KB Output is correct
60 Correct 256 ms 7112 KB Output is correct
61 Correct 264 ms 7876 KB Output is correct
62 Correct 253 ms 6344 KB Output is correct
63 Correct 274 ms 6704 KB Output is correct
64 Correct 252 ms 7884 KB Output is correct
65 Correct 0 ms 348 KB Output is correct
66 Correct 0 ms 348 KB Output is correct
67 Correct 263 ms 7884 KB Output is correct
68 Correct 263 ms 7108 KB Output is correct
69 Correct 243 ms 7864 KB Output is correct
70 Correct 258 ms 8132 KB Output is correct
71 Correct 256 ms 8128 KB Output is correct
72 Correct 256 ms 8392 KB Output is correct
73 Correct 246 ms 7884 KB Output is correct
74 Correct 263 ms 6692 KB Output is correct
75 Correct 255 ms 6860 KB Output is correct
76 Correct 262 ms 7588 KB Output is correct
77 Correct 62 ms 6856 KB Output is correct
78 Correct 31 ms 7108 KB Output is correct
79 Correct 45 ms 6596 KB Output is correct
80 Correct 47 ms 7628 KB Output is correct
81 Correct 43 ms 7620 KB Output is correct
82 Correct 40 ms 8140 KB Output is correct
83 Correct 33 ms 7616 KB Output is correct
84 Correct 173 ms 7372 KB Output is correct
85 Correct 267 ms 7616 KB Output is correct
86 Correct 112 ms 860 KB Output is correct
87 Correct 112 ms 1060 KB Output is correct
88 Correct 273 ms 8140 KB Output is correct
89 Correct 144 ms 2096 KB Output is correct
90 Correct 112 ms 1080 KB Output is correct