답안 #1034412

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1034412 2024-07-25T13:29:47 Z hasan2006 Chessboard (IZhO18_chessboard) C++17
100 / 100
663 ms 6232 KB
#include <bits/stdc++.h>

using namespace std;

#define TL ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);
#define rall(s) s.rbegin(),s.rend()
#define all(s) s.begin(),s.end()
#define pb push_back
#define se second
#define fi first
#define ll long long
#define ld long double
#define YES cout<<"YES\n"
#define Yes cout<<"Yes\n"
#define yes cout<<"yes\n"
#define NO cout<<"NO\n"
#define No cout<<"No\n"
#define no cout<<"no\n"


const int N = 5e5 + 9 , mod = 1e9 + 7;
ll a[N] , b[N] , dp[N] , c[N] , d[N] , X1[N] , X2[N] , Y1[N] , Y2[N];



pair<ll,ll> get(int p , int k ,int o){
    ll f = 0 ,x1 = X1[p] - 1 , y1 = Y1[p] - 1 , x2 = X2[p] - 1 , y2 = Y2[p] - 1 , s = 0 , j , ans = 0 , l = x2 - x1 + 1 , r = y2 - y1 + 1;
    if(y1 / k == y2 / k){
        if((y1 / k) % 2 == f)
            s += (y2 - y1 + 1);
    }else {
        if((y1 / k) % 2 == f)
            s += k - (y1 % k);
        y1 += k - (y1 % k);
        if((y2 / k) % 2 == f)
            s += (y2 % k) + 1;
        y2 -= (y2 % k) + 1;
        if(y1 <= y2){
            j = (y2 / k) - (y1 / k) + 1;
            j += ((y1 / k) % 2 == f);
            s += (j / 2) * k;
        }
    }
    if(x1 / k == x2 / k){
        if((x1 / k) % 2 == f)
            ans += (x2 - x1 + 1);
    }else {
        if((x1 / k) % 2 == f)
            ans += k - (x1 % k);
        x1 += k - (x1 % k);
        if((x2 / k) % 2 == f)
            ans += (x2 % k) + 1;
        x2 -= (x2 % k) + 1;
        if(x1 <= x2){
            j = (x2 / k) - (x1 / k) + 1;
            j += ((x1 / k) % 2 == f);
            ans += (j / 2) * k;
        }
    }
    if(f == 1 && k == 1)
        cout<<s<<" "<<ans <<" ";
    ans = (l - ans) * (r - s) +  (ans * s);
    pair<ll,ll>pa = {ans , l * r - ans};
    if(o)
        swap(pa.fi , pa.se);
    return pa;
}

void solve(){
    ll n , q , i , j ,l ,r , x , y , s = 0 , f , k , m , mn = 1e18, mx = 0 ;
    cin>>n>>k;
    vector<int>v;
    X1[0] = 1 , Y1[0] = 1 , X2[0] = n , Y2[0] = n;
    for(i = 1; i <= k; i++)
        cin>>X1[i]>>Y1[i]>>X2[i]>>Y2[i];
    for(i = 1; i * i <= n; i++)
        if(n % i == 0)
            v.pb(i) , v.pb(n / i);
    for(j = 0; j < 2; j++)
        for(auto l : v){
            ll ans = 0 , s = 0 , m = get(0 , l , j).fi;
            //cout<<m<<" ";
            for(i = 1; i <= k;  i++)
                s += get(i , l , j).fi , ans += get(i , l , j).se;
            if(l != n)
                ans += m - s , mn = min(mn , ans);
        }
    cout<<mn<<"\n";
}

int main(){
    TL;
    /*#ifndef ONLINE_JUDGE
        freopen("input.txt", "r", stdin);
        freopen("output.txt", "w", stdout);
    #endif*/
    int t = 1;
    //cin>>t;
    while(t--)
     {
        solve();
     }
}
// Author : حسن

Compilation message

chessboard.cpp: In function 'void solve()':
chessboard.cpp:70:12: warning: unused variable 'q' [-Wunused-variable]
   70 |     ll n , q , i , j ,l ,r , x , y , s = 0 , f , k , m , mn = 1e18, mx = 0 ;
      |            ^
chessboard.cpp:70:23: warning: unused variable 'l' [-Wunused-variable]
   70 |     ll n , q , i , j ,l ,r , x , y , s = 0 , f , k , m , mn = 1e18, mx = 0 ;
      |                       ^
chessboard.cpp:70:26: warning: unused variable 'r' [-Wunused-variable]
   70 |     ll n , q , i , j ,l ,r , x , y , s = 0 , f , k , m , mn = 1e18, mx = 0 ;
      |                          ^
chessboard.cpp:70:30: warning: unused variable 'x' [-Wunused-variable]
   70 |     ll n , q , i , j ,l ,r , x , y , s = 0 , f , k , m , mn = 1e18, mx = 0 ;
      |                              ^
chessboard.cpp:70:34: warning: unused variable 'y' [-Wunused-variable]
   70 |     ll n , q , i , j ,l ,r , x , y , s = 0 , f , k , m , mn = 1e18, mx = 0 ;
      |                                  ^
chessboard.cpp:70:38: warning: unused variable 's' [-Wunused-variable]
   70 |     ll n , q , i , j ,l ,r , x , y , s = 0 , f , k , m , mn = 1e18, mx = 0 ;
      |                                      ^
chessboard.cpp:70:46: warning: unused variable 'f' [-Wunused-variable]
   70 |     ll n , q , i , j ,l ,r , x , y , s = 0 , f , k , m , mn = 1e18, mx = 0 ;
      |                                              ^
chessboard.cpp:70:54: warning: unused variable 'm' [-Wunused-variable]
   70 |     ll n , q , i , j ,l ,r , x , y , s = 0 , f , k , m , mn = 1e18, mx = 0 ;
      |                                                      ^
chessboard.cpp:70:69: warning: unused variable 'mx' [-Wunused-variable]
   70 |     ll n , q , i , j ,l ,r , x , y , s = 0 , f , k , m , mn = 1e18, mx = 0 ;
      |                                                                     ^~
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 344 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
7 Correct 0 ms 344 KB Output is correct
8 Correct 1 ms 344 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 18 ms 3932 KB Output is correct
2 Correct 5 ms 1116 KB Output is correct
3 Correct 11 ms 2664 KB Output is correct
4 Correct 13 ms 2652 KB Output is correct
5 Correct 16 ms 3384 KB Output is correct
6 Correct 10 ms 2396 KB Output is correct
7 Correct 3 ms 1108 KB Output is correct
8 Correct 11 ms 2396 KB Output is correct
9 Correct 26 ms 5204 KB Output is correct
10 Correct 15 ms 3164 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 1 ms 468 KB Output is correct
4 Correct 1 ms 344 KB Output is correct
5 Correct 1 ms 348 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 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 1 ms 348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 1 ms 468 KB Output is correct
4 Correct 1 ms 344 KB Output is correct
5 Correct 1 ms 348 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 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 1 ms 348 KB Output is correct
16 Correct 14 ms 1628 KB Output is correct
17 Correct 21 ms 4440 KB Output is correct
18 Correct 36 ms 4956 KB Output is correct
19 Correct 120 ms 4604 KB Output is correct
20 Correct 141 ms 4952 KB Output is correct
21 Correct 20 ms 4188 KB Output is correct
22 Correct 1 ms 348 KB Output is correct
23 Correct 21 ms 2424 KB Output is correct
24 Correct 31 ms 4572 KB Output is correct
25 Correct 5 ms 860 KB Output is correct
26 Correct 19 ms 2924 KB Output is correct
27 Correct 30 ms 3676 KB Output is correct
28 Correct 41 ms 5208 KB Output is correct
29 Correct 9 ms 1884 KB Output is correct
30 Correct 1 ms 616 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 18 ms 3932 KB Output is correct
2 Correct 5 ms 1116 KB Output is correct
3 Correct 11 ms 2664 KB Output is correct
4 Correct 13 ms 2652 KB Output is correct
5 Correct 16 ms 3384 KB Output is correct
6 Correct 10 ms 2396 KB Output is correct
7 Correct 3 ms 1108 KB Output is correct
8 Correct 11 ms 2396 KB Output is correct
9 Correct 26 ms 5204 KB Output is correct
10 Correct 15 ms 3164 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 1 ms 348 KB Output is correct
13 Correct 1 ms 468 KB Output is correct
14 Correct 1 ms 344 KB Output is correct
15 Correct 1 ms 348 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 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 1 ms 348 KB Output is correct
26 Correct 14 ms 1628 KB Output is correct
27 Correct 21 ms 4440 KB Output is correct
28 Correct 36 ms 4956 KB Output is correct
29 Correct 120 ms 4604 KB Output is correct
30 Correct 141 ms 4952 KB Output is correct
31 Correct 20 ms 4188 KB Output is correct
32 Correct 1 ms 348 KB Output is correct
33 Correct 21 ms 2424 KB Output is correct
34 Correct 31 ms 4572 KB Output is correct
35 Correct 5 ms 860 KB Output is correct
36 Correct 19 ms 2924 KB Output is correct
37 Correct 30 ms 3676 KB Output is correct
38 Correct 41 ms 5208 KB Output is correct
39 Correct 9 ms 1884 KB Output is correct
40 Correct 1 ms 616 KB Output is correct
41 Correct 95 ms 5288 KB Output is correct
42 Correct 40 ms 5720 KB Output is correct
43 Correct 58 ms 5044 KB Output is correct
44 Correct 34 ms 5460 KB Output is correct
45 Correct 28 ms 5720 KB Output is correct
46 Correct 105 ms 5456 KB Output is correct
47 Correct 24 ms 5212 KB Output is correct
48 Correct 47 ms 5168 KB Output is correct
49 Correct 32 ms 4956 KB Output is correct
50 Correct 480 ms 5460 KB Output is correct
51 Correct 492 ms 6232 KB Output is correct
52 Correct 479 ms 5456 KB Output is correct
53 Correct 558 ms 5784 KB Output is correct
54 Correct 484 ms 5352 KB Output is correct
55 Correct 543 ms 5988 KB Output is correct
56 Correct 496 ms 5236 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 344 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
7 Correct 0 ms 344 KB Output is correct
8 Correct 1 ms 344 KB Output is correct
9 Correct 18 ms 3932 KB Output is correct
10 Correct 5 ms 1116 KB Output is correct
11 Correct 11 ms 2664 KB Output is correct
12 Correct 13 ms 2652 KB Output is correct
13 Correct 16 ms 3384 KB Output is correct
14 Correct 10 ms 2396 KB Output is correct
15 Correct 3 ms 1108 KB Output is correct
16 Correct 11 ms 2396 KB Output is correct
17 Correct 26 ms 5204 KB Output is correct
18 Correct 15 ms 3164 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 1 ms 348 KB Output is correct
21 Correct 1 ms 468 KB Output is correct
22 Correct 1 ms 344 KB Output is correct
23 Correct 1 ms 348 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 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 1 ms 348 KB Output is correct
34 Correct 14 ms 1628 KB Output is correct
35 Correct 21 ms 4440 KB Output is correct
36 Correct 36 ms 4956 KB Output is correct
37 Correct 120 ms 4604 KB Output is correct
38 Correct 141 ms 4952 KB Output is correct
39 Correct 20 ms 4188 KB Output is correct
40 Correct 1 ms 348 KB Output is correct
41 Correct 21 ms 2424 KB Output is correct
42 Correct 31 ms 4572 KB Output is correct
43 Correct 5 ms 860 KB Output is correct
44 Correct 19 ms 2924 KB Output is correct
45 Correct 30 ms 3676 KB Output is correct
46 Correct 41 ms 5208 KB Output is correct
47 Correct 9 ms 1884 KB Output is correct
48 Correct 1 ms 616 KB Output is correct
49 Correct 95 ms 5288 KB Output is correct
50 Correct 40 ms 5720 KB Output is correct
51 Correct 58 ms 5044 KB Output is correct
52 Correct 34 ms 5460 KB Output is correct
53 Correct 28 ms 5720 KB Output is correct
54 Correct 105 ms 5456 KB Output is correct
55 Correct 24 ms 5212 KB Output is correct
56 Correct 47 ms 5168 KB Output is correct
57 Correct 32 ms 4956 KB Output is correct
58 Correct 480 ms 5460 KB Output is correct
59 Correct 492 ms 6232 KB Output is correct
60 Correct 479 ms 5456 KB Output is correct
61 Correct 558 ms 5784 KB Output is correct
62 Correct 484 ms 5352 KB Output is correct
63 Correct 543 ms 5988 KB Output is correct
64 Correct 496 ms 5236 KB Output is correct
65 Correct 0 ms 348 KB Output is correct
66 Correct 0 ms 348 KB Output is correct
67 Correct 557 ms 5468 KB Output is correct
68 Correct 547 ms 5456 KB Output is correct
69 Correct 513 ms 4940 KB Output is correct
70 Correct 590 ms 5456 KB Output is correct
71 Correct 611 ms 5380 KB Output is correct
72 Correct 566 ms 5292 KB Output is correct
73 Correct 576 ms 5164 KB Output is correct
74 Correct 606 ms 5464 KB Output is correct
75 Correct 567 ms 5344 KB Output is correct
76 Correct 631 ms 5460 KB Output is correct
77 Correct 115 ms 5716 KB Output is correct
78 Correct 38 ms 5212 KB Output is correct
79 Correct 72 ms 4972 KB Output is correct
80 Correct 75 ms 5212 KB Output is correct
81 Correct 74 ms 4948 KB Output is correct
82 Correct 61 ms 5452 KB Output is correct
83 Correct 47 ms 5212 KB Output is correct
84 Correct 378 ms 5972 KB Output is correct
85 Correct 633 ms 5720 KB Output is correct
86 Correct 1 ms 344 KB Output is correct
87 Correct 0 ms 344 KB Output is correct
88 Correct 663 ms 5984 KB Output is correct
89 Correct 130 ms 1368 KB Output is correct
90 Correct 0 ms 344 KB Output is correct