답안 #1107911

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1107911 2024-11-02T10:10:29 Z KasymK Chessboard (IZhO18_chessboard) C++17
70 / 100
369 ms 8560 KB
#include "bits/stdc++.h"
using namespace std;
#define ff first
#define ss second
#define all(v) v.begin(), v.end()
#define ll long long
#define pb push_back
#define pii pair<int, int>
#define pli pair<ll, int>
#define pll pair<ll, ll>
#define tr(i, c) for(auto i = c.begin(); i != c.end(); ++i)
#define wr puts("----------------")
template<class T>bool umin(T& a,T b){if(a>b){a=b;return 1;}return 0;}
template<class T>bool umax(T& a,T b){if(a<b){a=b;return 1;}return 0;}
const ll INF = 1e18;
#define int long long
using node = tuple<int, int, int, int>;
int answer = INF;
vector<node> adj;
int n, kk;

int f(int x, int y, int xx){
    int sm = 0, _x = (x/xx)*xx, _y = (y/xx)*xx;
    if((_x/xx+_y/xx)&1){
        sm += ((_x/xx)*(_y/xx))/2*(xx*xx);
        sm += (_y/xx+1)/2*(x-_x)*xx;
        sm += (_x/xx+1)/2*(y-_y)*xx;
    }
    else{
        sm += ((_x/xx)*(_y /xx)+1)/2*(xx*xx);
        sm += (_y/xx)/2*(x-_x)*xx;
        sm += ((_x/xx))/2*(y-_y)*xx;
        sm += (x-_x)*(y-_y);
    }
    return sm;
}

void solve(int x){
    int ans = n*n-f(n, n, x);
    for(auto xx : adj){
        int a, b, c, d;
        tie(a, b, c, d) = xx;
        int w = f(c, d, x)+f(a-1, b-1, x)-f(c, b-1, x)-f(a-1, d, x);
        ans += w, ans -= (c-a+1)*(d-b+1)-w;
    }
    umin(answer, ans);
    umin(answer, n*n-ans);
}

signed main(){
    // freopen("file.txt", "r", stdin);
    scanf("%lld%lld", &n, &kk);
    bool done = 1;
    for(int i = 1; i <= kk; ++i){
        int a, b, c, d;
        scanf("%lld%lld%lld%lld", &a, &b, &c, &d);
        adj.pb({a, b, c, d});
        done &= (a==c and b==d);
    }
    assert(done);
    for(int i = 1; i*i <= n; ++i){
        if(n%i==0){
        solve(i);
        if(i!=n/i and i>1)
            solve(n/i);
        }
    }
    printf("%lld\n", answer);
    return 0;
}

Compilation message

chessboard.cpp: In function 'int main()':
chessboard.cpp:52:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   52 |     scanf("%lld%lld", &n, &kk);
      |     ~~~~~^~~~~~~~~~~~~~~~~~~~~
chessboard.cpp:56:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   56 |         scanf("%lld%lld%lld%lld", &a, &b, &c, &d);
      |         ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 336 KB Output is correct
2 Correct 1 ms 336 KB Output is correct
3 Correct 1 ms 336 KB Output is correct
4 Correct 1 ms 336 KB Output is correct
5 Correct 1 ms 336 KB Output is correct
6 Correct 1 ms 336 KB Output is correct
7 Correct 1 ms 336 KB Output is correct
8 Correct 1 ms 348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 17 ms 3584 KB Output is correct
2 Correct 7 ms 1736 KB Output is correct
3 Correct 14 ms 4548 KB Output is correct
4 Correct 14 ms 4036 KB Output is correct
5 Correct 18 ms 4460 KB Output is correct
6 Correct 13 ms 4292 KB Output is correct
7 Correct 4 ms 848 KB Output is correct
8 Correct 12 ms 4304 KB Output is correct
9 Correct 32 ms 6852 KB Output is correct
10 Correct 14 ms 4548 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 512 KB Output is correct
2 Correct 1 ms 336 KB Output is correct
3 Correct 1 ms 504 KB Output is correct
4 Correct 1 ms 336 KB Output is correct
5 Correct 1 ms 336 KB Output is correct
6 Correct 1 ms 336 KB Output is correct
7 Correct 1 ms 336 KB Output is correct
8 Correct 1 ms 336 KB Output is correct
9 Correct 1 ms 336 KB Output is correct
10 Correct 1 ms 336 KB Output is correct
11 Correct 1 ms 336 KB Output is correct
12 Correct 2 ms 336 KB Output is correct
13 Correct 1 ms 336 KB Output is correct
14 Correct 1 ms 336 KB Output is correct
15 Correct 1 ms 336 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 512 KB Output is correct
2 Correct 1 ms 336 KB Output is correct
3 Correct 1 ms 504 KB Output is correct
4 Correct 1 ms 336 KB Output is correct
5 Correct 1 ms 336 KB Output is correct
6 Correct 1 ms 336 KB Output is correct
7 Correct 1 ms 336 KB Output is correct
8 Correct 1 ms 336 KB Output is correct
9 Correct 1 ms 336 KB Output is correct
10 Correct 1 ms 336 KB Output is correct
11 Correct 1 ms 336 KB Output is correct
12 Correct 2 ms 336 KB Output is correct
13 Correct 1 ms 336 KB Output is correct
14 Correct 1 ms 336 KB Output is correct
15 Correct 1 ms 336 KB Output is correct
16 Correct 10 ms 1992 KB Output is correct
17 Correct 23 ms 7872 KB Output is correct
18 Correct 34 ms 7616 KB Output is correct
19 Correct 98 ms 7916 KB Output is correct
20 Correct 107 ms 7872 KB Output is correct
21 Correct 23 ms 7884 KB Output is correct
22 Correct 1 ms 336 KB Output is correct
23 Correct 21 ms 4316 KB Output is correct
24 Correct 28 ms 7872 KB Output is correct
25 Correct 6 ms 1228 KB Output is correct
26 Correct 25 ms 4036 KB Output is correct
27 Correct 29 ms 7616 KB Output is correct
28 Correct 55 ms 7828 KB Output is correct
29 Correct 13 ms 4036 KB Output is correct
30 Correct 2 ms 592 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 17 ms 3584 KB Output is correct
2 Correct 7 ms 1736 KB Output is correct
3 Correct 14 ms 4548 KB Output is correct
4 Correct 14 ms 4036 KB Output is correct
5 Correct 18 ms 4460 KB Output is correct
6 Correct 13 ms 4292 KB Output is correct
7 Correct 4 ms 848 KB Output is correct
8 Correct 12 ms 4304 KB Output is correct
9 Correct 32 ms 6852 KB Output is correct
10 Correct 14 ms 4548 KB Output is correct
11 Correct 1 ms 512 KB Output is correct
12 Correct 1 ms 336 KB Output is correct
13 Correct 1 ms 504 KB Output is correct
14 Correct 1 ms 336 KB Output is correct
15 Correct 1 ms 336 KB Output is correct
16 Correct 1 ms 336 KB Output is correct
17 Correct 1 ms 336 KB Output is correct
18 Correct 1 ms 336 KB Output is correct
19 Correct 1 ms 336 KB Output is correct
20 Correct 1 ms 336 KB Output is correct
21 Correct 1 ms 336 KB Output is correct
22 Correct 2 ms 336 KB Output is correct
23 Correct 1 ms 336 KB Output is correct
24 Correct 1 ms 336 KB Output is correct
25 Correct 1 ms 336 KB Output is correct
26 Correct 10 ms 1992 KB Output is correct
27 Correct 23 ms 7872 KB Output is correct
28 Correct 34 ms 7616 KB Output is correct
29 Correct 98 ms 7916 KB Output is correct
30 Correct 107 ms 7872 KB Output is correct
31 Correct 23 ms 7884 KB Output is correct
32 Correct 1 ms 336 KB Output is correct
33 Correct 21 ms 4316 KB Output is correct
34 Correct 28 ms 7872 KB Output is correct
35 Correct 6 ms 1228 KB Output is correct
36 Correct 25 ms 4036 KB Output is correct
37 Correct 29 ms 7616 KB Output is correct
38 Correct 55 ms 7828 KB Output is correct
39 Correct 13 ms 4036 KB Output is correct
40 Correct 2 ms 592 KB Output is correct
41 Correct 78 ms 8560 KB Output is correct
42 Correct 37 ms 8384 KB Output is correct
43 Correct 52 ms 8384 KB Output is correct
44 Correct 36 ms 8384 KB Output is correct
45 Correct 30 ms 8504 KB Output is correct
46 Correct 85 ms 8460 KB Output is correct
47 Correct 27 ms 8552 KB Output is correct
48 Correct 45 ms 7352 KB Output is correct
49 Correct 47 ms 8384 KB Output is correct
50 Correct 341 ms 8384 KB Output is correct
51 Correct 369 ms 8384 KB Output is correct
52 Correct 338 ms 8384 KB Output is correct
53 Correct 359 ms 7864 KB Output is correct
54 Correct 319 ms 8384 KB Output is correct
55 Correct 361 ms 8384 KB Output is correct
56 Correct 343 ms 8128 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 336 KB Output is correct
2 Correct 1 ms 336 KB Output is correct
3 Correct 1 ms 336 KB Output is correct
4 Correct 1 ms 336 KB Output is correct
5 Correct 1 ms 336 KB Output is correct
6 Correct 1 ms 336 KB Output is correct
7 Correct 1 ms 336 KB Output is correct
8 Correct 1 ms 348 KB Output is correct
9 Correct 17 ms 3584 KB Output is correct
10 Correct 7 ms 1736 KB Output is correct
11 Correct 14 ms 4548 KB Output is correct
12 Correct 14 ms 4036 KB Output is correct
13 Correct 18 ms 4460 KB Output is correct
14 Correct 13 ms 4292 KB Output is correct
15 Correct 4 ms 848 KB Output is correct
16 Correct 12 ms 4304 KB Output is correct
17 Correct 32 ms 6852 KB Output is correct
18 Correct 14 ms 4548 KB Output is correct
19 Correct 1 ms 512 KB Output is correct
20 Correct 1 ms 336 KB Output is correct
21 Correct 1 ms 504 KB Output is correct
22 Correct 1 ms 336 KB Output is correct
23 Correct 1 ms 336 KB Output is correct
24 Correct 1 ms 336 KB Output is correct
25 Correct 1 ms 336 KB Output is correct
26 Correct 1 ms 336 KB Output is correct
27 Correct 1 ms 336 KB Output is correct
28 Correct 1 ms 336 KB Output is correct
29 Correct 1 ms 336 KB Output is correct
30 Correct 2 ms 336 KB Output is correct
31 Correct 1 ms 336 KB Output is correct
32 Correct 1 ms 336 KB Output is correct
33 Correct 1 ms 336 KB Output is correct
34 Correct 10 ms 1992 KB Output is correct
35 Correct 23 ms 7872 KB Output is correct
36 Correct 34 ms 7616 KB Output is correct
37 Correct 98 ms 7916 KB Output is correct
38 Correct 107 ms 7872 KB Output is correct
39 Correct 23 ms 7884 KB Output is correct
40 Correct 1 ms 336 KB Output is correct
41 Correct 21 ms 4316 KB Output is correct
42 Correct 28 ms 7872 KB Output is correct
43 Correct 6 ms 1228 KB Output is correct
44 Correct 25 ms 4036 KB Output is correct
45 Correct 29 ms 7616 KB Output is correct
46 Correct 55 ms 7828 KB Output is correct
47 Correct 13 ms 4036 KB Output is correct
48 Correct 2 ms 592 KB Output is correct
49 Correct 78 ms 8560 KB Output is correct
50 Correct 37 ms 8384 KB Output is correct
51 Correct 52 ms 8384 KB Output is correct
52 Correct 36 ms 8384 KB Output is correct
53 Correct 30 ms 8504 KB Output is correct
54 Correct 85 ms 8460 KB Output is correct
55 Correct 27 ms 8552 KB Output is correct
56 Correct 45 ms 7352 KB Output is correct
57 Correct 47 ms 8384 KB Output is correct
58 Correct 341 ms 8384 KB Output is correct
59 Correct 369 ms 8384 KB Output is correct
60 Correct 338 ms 8384 KB Output is correct
61 Correct 359 ms 7864 KB Output is correct
62 Correct 319 ms 8384 KB Output is correct
63 Correct 361 ms 8384 KB Output is correct
64 Correct 343 ms 8128 KB Output is correct
65 Correct 1 ms 336 KB Output is correct
66 Runtime error 1 ms 336 KB Execution killed with signal 6
67 Halted 0 ms 0 KB -