답안 #805695

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
805695 2023-08-03T20:37:56 Z farhan132 Chessboard (IZhO18_chessboard) C++17
100 / 100
1181 ms 6384 KB
/***Farhan132***/
// #pragma GCC optimize("Ofast,fast-math")
// #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,avx2,fma")
// #pragma GCC optimization ("unroll-loops")

#include <bits/stdc++.h>
 
using namespace std;
 
typedef long long ll;
typedef double dd;
typedef pair<ll , ll> ii;
typedef tuple < ll,  ll, ll > tp;
 
#define ff first
#define ss second
#define pb push_back
#define in insert
#define bug printf("**!\n")
#define mem(a , b) memset(a, b ,sizeof(a))
#define front_zero(n) __builtin_clz(n)
#define back_zero(n) __builtin_ctzll(n)
#define total_one(n) __builtin_popcount(n)
#define clean fflush(stdout)
 
const ll mod =  (ll) 998244353;
// const ll mod =  (ll) 1e9 + 7;
//const ll INF = numeric_limits<ll>::max()-1;
const ll INF = (ll)2e18;
 
// ll dx[]={0,1,0,-1};
// ll dy[]={1,0,-1,0};
// ll dxx[]={0,1,0,-1,1,1,-1,-1};
// ll dyy[]={1,0,-1,0,1,-1,1,-1};
 
mt19937 rng(chrono::system_clock::now().time_since_epoch().count());
 
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
 
template <typename T> using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

const ll N = 2005;

ii add(ii a, ii b){
    return {a.ff + b.ff, a.ss + b.ss};
}
ii sub(ii a, ii b){
    return {a.ff - b.ff, a.ss - b.ss};
}

ii f(ll col, ll h, ll sz, ll n){
    ll nor = n / (2 * sz);
    ii ans = {nor * sz, nor * sz};
    n %= (2 * sz);
    if(n > sz){
        ans.ff += sz;
        ans.ss += n - sz;
    }else{
        ans.ff += n;
    }
    ans.ff *= h;
    ans.ss *= h;
    if(!col) swap(ans.ff, ans.ss);
    return ans;
}

ii corner(ll x, ll y, ll sz){
    if(min(x, y) < 1) return {0, 0}; 
    ll p1 = x / sz;
    ll p2 = y / sz;
    ll unit = sz * sz;
    ii ans = {unit * ((p1 * p2 + 1) / 2), unit * ((p1 * p2) / 2)};

    ans = add(ans, f(1 - p1%2, x % sz, sz, y));
    ans = add(ans, f(1 - p2%2, y % sz, sz, p1 * sz));
    return ans;
}
ii F(ll r1, ll c1, ll r2, ll c2, ll sz){
    ii ans = corner(r2, c2, sz);
    ans = sub(ans, corner(r2, c1 - 1, sz));
    ans = sub(ans, corner(r1 - 1, c2, sz));
    ans = add(ans, corner(r1 - 1, c1 - 1, sz));
    return ans;
}

void solve(){

    ll n; cin >> n; 

    vector < tuple < ll , ll , ll , ll > > Q;

    ll q; cin >> q;
    for(ll i = 0; i < q; i++){
        ll r1, c1, r2, c2;
        cin >> r1 >> c1 >> r2 >> c2;
        Q.push_back({r1, c1, r2, c2});
    }
    ll ans = n * n;

    for(ll sz = 1; sz < n; sz++){
        if(n % sz != 0) continue;
        ii cnt = {0, 0};
        for(auto [r1, c1, r2, c2] : Q){
            cnt = add(cnt, F(r1, c1, r2, c2, sz));
        }
        ii overall = corner(n, n, sz);
        ans = min({ans, cnt.ss + overall.ff - cnt.ff, cnt.ff + overall.ss - cnt.ss});
    }
    cout << ans << '\n';
    
   return;
}

int main() {

    #ifdef LOCAL
        freopen("in.txt", "r", stdin);
        freopen("out.txt", "w", stdout);
        auto start_time = clock();
    #else
         // freopen("subsequence.in", "r", stdin);
         // freopen("subsequence.out", "w", stdout); 
         ios_base::sync_with_stdio(0); cin.tie(NULL); cout.tie(NULL);
    #endif

    //precalc();
 
    ll T = 1, CT = 0; //cin >> T; 
 
    while(T--){
        // cout << "Case #" << ++CT << ": ";
        solve();
    }
    
    #ifdef LOCAL
        auto end_time = clock();
        cerr<< "Execution time: "<<(end_time - start_time)*(int)1e3/CLOCKS_PER_SEC<<" ms\n";
    #endif
 
    return 0;
} 

Compilation message

chessboard.cpp: In function 'int main()':
chessboard.cpp:130:15: warning: unused variable 'CT' [-Wunused-variable]
  130 |     ll T = 1, CT = 0; //cin >> T;
      |               ^~
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 22 ms 2512 KB Output is correct
2 Correct 9 ms 1844 KB Output is correct
3 Correct 15 ms 3408 KB Output is correct
4 Correct 16 ms 3280 KB Output is correct
5 Correct 20 ms 3532 KB Output is correct
6 Correct 13 ms 3276 KB Output is correct
7 Correct 5 ms 852 KB Output is correct
8 Correct 13 ms 3280 KB Output is correct
9 Correct 33 ms 6212 KB Output is correct
10 Correct 19 ms 3528 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 1 ms 360 KB Output is correct
10 Correct 0 ms 212 KB Output is correct
11 Correct 1 ms 324 KB Output is correct
12 Correct 1 ms 328 KB Output is correct
13 Correct 1 ms 340 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
15 Correct 1 ms 328 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 1 ms 360 KB Output is correct
10 Correct 0 ms 212 KB Output is correct
11 Correct 1 ms 324 KB Output is correct
12 Correct 1 ms 328 KB Output is correct
13 Correct 1 ms 340 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
15 Correct 1 ms 328 KB Output is correct
16 Correct 15 ms 1936 KB Output is correct
17 Correct 26 ms 5848 KB Output is correct
18 Correct 46 ms 5816 KB Output is correct
19 Correct 215 ms 5828 KB Output is correct
20 Correct 240 ms 5756 KB Output is correct
21 Correct 27 ms 5744 KB Output is correct
22 Correct 1 ms 340 KB Output is correct
23 Correct 36 ms 3128 KB Output is correct
24 Correct 47 ms 5736 KB Output is correct
25 Correct 7 ms 1112 KB Output is correct
26 Correct 26 ms 3280 KB Output is correct
27 Correct 44 ms 5576 KB Output is correct
28 Correct 51 ms 5728 KB Output is correct
29 Correct 10 ms 3052 KB Output is correct
30 Correct 2 ms 468 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 22 ms 2512 KB Output is correct
2 Correct 9 ms 1844 KB Output is correct
3 Correct 15 ms 3408 KB Output is correct
4 Correct 16 ms 3280 KB Output is correct
5 Correct 20 ms 3532 KB Output is correct
6 Correct 13 ms 3276 KB Output is correct
7 Correct 5 ms 852 KB Output is correct
8 Correct 13 ms 3280 KB Output is correct
9 Correct 33 ms 6212 KB Output is correct
10 Correct 19 ms 3528 KB Output is correct
11 Correct 1 ms 340 KB Output is correct
12 Correct 0 ms 212 KB Output is correct
13 Correct 1 ms 340 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
15 Correct 1 ms 340 KB Output is correct
16 Correct 1 ms 340 KB Output is correct
17 Correct 1 ms 340 KB Output is correct
18 Correct 1 ms 340 KB Output is correct
19 Correct 1 ms 360 KB Output is correct
20 Correct 0 ms 212 KB Output is correct
21 Correct 1 ms 324 KB Output is correct
22 Correct 1 ms 328 KB Output is correct
23 Correct 1 ms 340 KB Output is correct
24 Correct 1 ms 340 KB Output is correct
25 Correct 1 ms 328 KB Output is correct
26 Correct 15 ms 1936 KB Output is correct
27 Correct 26 ms 5848 KB Output is correct
28 Correct 46 ms 5816 KB Output is correct
29 Correct 215 ms 5828 KB Output is correct
30 Correct 240 ms 5756 KB Output is correct
31 Correct 27 ms 5744 KB Output is correct
32 Correct 1 ms 340 KB Output is correct
33 Correct 36 ms 3128 KB Output is correct
34 Correct 47 ms 5736 KB Output is correct
35 Correct 7 ms 1112 KB Output is correct
36 Correct 26 ms 3280 KB Output is correct
37 Correct 44 ms 5576 KB Output is correct
38 Correct 51 ms 5728 KB Output is correct
39 Correct 10 ms 3052 KB Output is correct
40 Correct 2 ms 468 KB Output is correct
41 Correct 194 ms 6292 KB Output is correct
42 Correct 52 ms 6340 KB Output is correct
43 Correct 109 ms 6328 KB Output is correct
44 Correct 56 ms 6340 KB Output is correct
45 Correct 35 ms 6316 KB Output is correct
46 Correct 218 ms 6240 KB Output is correct
47 Correct 32 ms 6348 KB Output is correct
48 Correct 84 ms 6344 KB Output is correct
49 Correct 47 ms 6240 KB Output is correct
50 Correct 1061 ms 6320 KB Output is correct
51 Correct 1135 ms 6344 KB Output is correct
52 Correct 1056 ms 6340 KB Output is correct
53 Correct 1124 ms 6252 KB Output is correct
54 Correct 1032 ms 6352 KB Output is correct
55 Correct 1170 ms 6340 KB Output is correct
56 Correct 1002 ms 6348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 22 ms 2512 KB Output is correct
10 Correct 9 ms 1844 KB Output is correct
11 Correct 15 ms 3408 KB Output is correct
12 Correct 16 ms 3280 KB Output is correct
13 Correct 20 ms 3532 KB Output is correct
14 Correct 13 ms 3276 KB Output is correct
15 Correct 5 ms 852 KB Output is correct
16 Correct 13 ms 3280 KB Output is correct
17 Correct 33 ms 6212 KB Output is correct
18 Correct 19 ms 3528 KB Output is correct
19 Correct 1 ms 340 KB Output is correct
20 Correct 0 ms 212 KB Output is correct
21 Correct 1 ms 340 KB Output is correct
22 Correct 1 ms 340 KB Output is correct
23 Correct 1 ms 340 KB Output is correct
24 Correct 1 ms 340 KB Output is correct
25 Correct 1 ms 340 KB Output is correct
26 Correct 1 ms 340 KB Output is correct
27 Correct 1 ms 360 KB Output is correct
28 Correct 0 ms 212 KB Output is correct
29 Correct 1 ms 324 KB Output is correct
30 Correct 1 ms 328 KB Output is correct
31 Correct 1 ms 340 KB Output is correct
32 Correct 1 ms 340 KB Output is correct
33 Correct 1 ms 328 KB Output is correct
34 Correct 15 ms 1936 KB Output is correct
35 Correct 26 ms 5848 KB Output is correct
36 Correct 46 ms 5816 KB Output is correct
37 Correct 215 ms 5828 KB Output is correct
38 Correct 240 ms 5756 KB Output is correct
39 Correct 27 ms 5744 KB Output is correct
40 Correct 1 ms 340 KB Output is correct
41 Correct 36 ms 3128 KB Output is correct
42 Correct 47 ms 5736 KB Output is correct
43 Correct 7 ms 1112 KB Output is correct
44 Correct 26 ms 3280 KB Output is correct
45 Correct 44 ms 5576 KB Output is correct
46 Correct 51 ms 5728 KB Output is correct
47 Correct 10 ms 3052 KB Output is correct
48 Correct 2 ms 468 KB Output is correct
49 Correct 194 ms 6292 KB Output is correct
50 Correct 52 ms 6340 KB Output is correct
51 Correct 109 ms 6328 KB Output is correct
52 Correct 56 ms 6340 KB Output is correct
53 Correct 35 ms 6316 KB Output is correct
54 Correct 218 ms 6240 KB Output is correct
55 Correct 32 ms 6348 KB Output is correct
56 Correct 84 ms 6344 KB Output is correct
57 Correct 47 ms 6240 KB Output is correct
58 Correct 1061 ms 6320 KB Output is correct
59 Correct 1135 ms 6344 KB Output is correct
60 Correct 1056 ms 6340 KB Output is correct
61 Correct 1124 ms 6252 KB Output is correct
62 Correct 1032 ms 6352 KB Output is correct
63 Correct 1170 ms 6340 KB Output is correct
64 Correct 1002 ms 6348 KB Output is correct
65 Correct 0 ms 320 KB Output is correct
66 Correct 0 ms 212 KB Output is correct
67 Correct 1100 ms 6300 KB Output is correct
68 Correct 1098 ms 6328 KB Output is correct
69 Correct 960 ms 6348 KB Output is correct
70 Correct 1074 ms 6348 KB Output is correct
71 Correct 1051 ms 6312 KB Output is correct
72 Correct 1030 ms 6340 KB Output is correct
73 Correct 1012 ms 6348 KB Output is correct
74 Correct 1092 ms 6348 KB Output is correct
75 Correct 1050 ms 6384 KB Output is correct
76 Correct 1109 ms 6344 KB Output is correct
77 Correct 161 ms 6348 KB Output is correct
78 Correct 49 ms 6156 KB Output is correct
79 Correct 107 ms 6256 KB Output is correct
80 Correct 118 ms 6340 KB Output is correct
81 Correct 106 ms 6240 KB Output is correct
82 Correct 85 ms 6320 KB Output is correct
83 Correct 62 ms 6368 KB Output is correct
84 Correct 652 ms 6224 KB Output is correct
85 Correct 1154 ms 6340 KB Output is correct
86 Correct 2 ms 212 KB Output is correct
87 Correct 1 ms 212 KB Output is correct
88 Correct 1181 ms 6348 KB Output is correct
89 Correct 222 ms 1876 KB Output is correct
90 Correct 1 ms 212 KB Output is correct