Submission #1112613

# Submission time Handle Problem Language Result Execution time Memory
1112613 2024-11-14T12:16:04 Z vjudge1 Chessboard (IZhO18_chessboard) C++17
47 / 100
2000 ms 9700 KB
//Dost SEFEROĞLU
#pragma GCC optimize("O3,unroll-loops")
#pragma GCC target("avx2")
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define pii pair<int,int>
#define ff first
#define ss second
#define sp << " " << 
#define vi vector<int>
#define all(xx) xx.begin(),xx.end()
#define ps(xxx) cout << (xxx) << endl;
const int N = 5e2+1,inf = 1e16,MOD = 1e9+7; 
 

int32_t t[400001],lazy[400001];
inline void push(const int& node,const int& l,const int& r) {
    if (!lazy[node]) return;
    t[node] = (r-l+1)-t[node];
    if (l != r) {
        lazy[2*node]^=1;
        lazy[2*node+1]^=1;
    }
    lazy[node] = 0;
}
void update(int node,int l,int r,int L,int R) {
    push(node,l,r);
    if (l > R || r < L) return;
    if (l >= L && r <= R) {
        lazy[node]^=1;
        push(node,l,r);
        return;
    }
    int m = (l+r) >> 1;
    update(2*node,l,m,L,R),update(2*node+1,m+1,r,L,R);
    t[node] = t[2*node]+t[2*node+1];
}
void solve() { 
    int n,k;
    cin >> n >> k;
    vector<pii> upds[n+2];
    for (int i=1;i<=k;i++) {
        int x1,y1,x2,y2;
        cin >> x1 >> y1 >> x2 >> y2;
        upds[x1].push_back({y1,y2});
        upds[x2+1].push_back({y1,y2});
    }
    vi divs;
    for (int i=1;i<n;i++) if (n%i == 0) divs.push_back(i);
    int ans = inf;
    for (int d : divs) {
        int cur = 1;
        int fl = 0;
        while (cur <= n) {
            if (!fl) update(1,1,n,cur,cur+d-1);
            cur+=d;
            fl^=1;
        }
        int need = 0;
        for (int j = 1;j<=n+1;j++) {
            for (auto it : upds[j]) update(1,1,n,it.ff,it.ss);
            if (j > n) break;
            push(1,1,n);
            int q = t[1];
            if (((j-1)/d)%2 == 0) need+=q;
            else need+=n-q;
        }
        ans = min(ans,need);
        ans = min(ans,n*n-need);
        cur = 1;
        fl = 0;
        while (cur <= n) {
            if (!fl) update(1,1,n,cur,cur+d-1);
            cur+=d;
            fl^=1;
        }
    }
    cout << ans << endl;
}  
 
                
                            
signed main() { 
    ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    #ifdef Dodi
        freopen("in.txt","r",stdin);
        freopen("out.txt","w",stdout);
    #endif
    int t = 1;
    //cin >> t; 
    while (t --> 0) solve();
}
# Verdict Execution time Memory 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 504 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
# Verdict Execution time Memory Grader output
1 Correct 54 ms 5960 KB Output is correct
2 Correct 13 ms 2016 KB Output is correct
3 Correct 43 ms 6224 KB Output is correct
4 Correct 22 ms 3064 KB Output is correct
5 Correct 47 ms 5324 KB Output is correct
6 Correct 33 ms 4176 KB Output is correct
7 Correct 9 ms 1616 KB Output is correct
8 Correct 32 ms 4176 KB Output is correct
9 Correct 68 ms 6076 KB Output is correct
10 Correct 47 ms 4664 KB Output is correct
# Verdict Execution time Memory 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 2 ms 336 KB Output is correct
5 Correct 2 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 1 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
# Verdict Execution time Memory 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 2 ms 336 KB Output is correct
5 Correct 2 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 1 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 22 ms 1872 KB Output is correct
17 Correct 33 ms 4944 KB Output is correct
18 Correct 85 ms 4944 KB Output is correct
19 Correct 461 ms 4688 KB Output is correct
20 Correct 550 ms 4732 KB Output is correct
21 Correct 34 ms 4944 KB Output is correct
22 Correct 2 ms 336 KB Output is correct
23 Correct 67 ms 2600 KB Output is correct
24 Correct 72 ms 4688 KB Output is correct
25 Correct 14 ms 848 KB Output is correct
26 Correct 45 ms 2896 KB Output is correct
27 Correct 84 ms 4432 KB Output is correct
28 Correct 74 ms 4700 KB Output is correct
29 Correct 14 ms 2568 KB Output is correct
30 Correct 3 ms 592 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 54 ms 5960 KB Output is correct
2 Correct 13 ms 2016 KB Output is correct
3 Correct 43 ms 6224 KB Output is correct
4 Correct 22 ms 3064 KB Output is correct
5 Correct 47 ms 5324 KB Output is correct
6 Correct 33 ms 4176 KB Output is correct
7 Correct 9 ms 1616 KB Output is correct
8 Correct 32 ms 4176 KB Output is correct
9 Correct 68 ms 6076 KB Output is correct
10 Correct 47 ms 4664 KB Output is correct
11 Correct 1 ms 336 KB Output is correct
12 Correct 1 ms 336 KB Output is correct
13 Correct 1 ms 336 KB Output is correct
14 Correct 2 ms 336 KB Output is correct
15 Correct 2 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 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 22 ms 1872 KB Output is correct
27 Correct 33 ms 4944 KB Output is correct
28 Correct 85 ms 4944 KB Output is correct
29 Correct 461 ms 4688 KB Output is correct
30 Correct 550 ms 4732 KB Output is correct
31 Correct 34 ms 4944 KB Output is correct
32 Correct 2 ms 336 KB Output is correct
33 Correct 67 ms 2600 KB Output is correct
34 Correct 72 ms 4688 KB Output is correct
35 Correct 14 ms 848 KB Output is correct
36 Correct 45 ms 2896 KB Output is correct
37 Correct 84 ms 4432 KB Output is correct
38 Correct 74 ms 4700 KB Output is correct
39 Correct 14 ms 2568 KB Output is correct
40 Correct 3 ms 592 KB Output is correct
41 Correct 803 ms 9032 KB Output is correct
42 Correct 155 ms 9544 KB Output is correct
43 Correct 382 ms 9032 KB Output is correct
44 Correct 171 ms 9520 KB Output is correct
45 Correct 81 ms 9544 KB Output is correct
46 Correct 814 ms 9700 KB Output is correct
47 Correct 82 ms 9032 KB Output is correct
48 Correct 257 ms 9332 KB Output is correct
49 Correct 133 ms 9116 KB Output is correct
50 Execution timed out 2067 ms 9032 KB Time limit exceeded
51 Halted 0 ms 0 KB -
# Verdict Execution time Memory 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 504 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 54 ms 5960 KB Output is correct
10 Correct 13 ms 2016 KB Output is correct
11 Correct 43 ms 6224 KB Output is correct
12 Correct 22 ms 3064 KB Output is correct
13 Correct 47 ms 5324 KB Output is correct
14 Correct 33 ms 4176 KB Output is correct
15 Correct 9 ms 1616 KB Output is correct
16 Correct 32 ms 4176 KB Output is correct
17 Correct 68 ms 6076 KB Output is correct
18 Correct 47 ms 4664 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 2 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 1 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 22 ms 1872 KB Output is correct
35 Correct 33 ms 4944 KB Output is correct
36 Correct 85 ms 4944 KB Output is correct
37 Correct 461 ms 4688 KB Output is correct
38 Correct 550 ms 4732 KB Output is correct
39 Correct 34 ms 4944 KB Output is correct
40 Correct 2 ms 336 KB Output is correct
41 Correct 67 ms 2600 KB Output is correct
42 Correct 72 ms 4688 KB Output is correct
43 Correct 14 ms 848 KB Output is correct
44 Correct 45 ms 2896 KB Output is correct
45 Correct 84 ms 4432 KB Output is correct
46 Correct 74 ms 4700 KB Output is correct
47 Correct 14 ms 2568 KB Output is correct
48 Correct 3 ms 592 KB Output is correct
49 Correct 803 ms 9032 KB Output is correct
50 Correct 155 ms 9544 KB Output is correct
51 Correct 382 ms 9032 KB Output is correct
52 Correct 171 ms 9520 KB Output is correct
53 Correct 81 ms 9544 KB Output is correct
54 Correct 814 ms 9700 KB Output is correct
55 Correct 82 ms 9032 KB Output is correct
56 Correct 257 ms 9332 KB Output is correct
57 Correct 133 ms 9116 KB Output is correct
58 Execution timed out 2067 ms 9032 KB Time limit exceeded
59 Halted 0 ms 0 KB -