Submission #1112627

# Submission time Handle Problem Language Result Execution time Memory
1112627 2024-11-14T12:51:38 Z dosts Chessboard (IZhO18_chessboard) C++17
100 / 100
249 ms 12360 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; 
 

void solve() { 
    int n,k;
    cin >> n >> k;
    vector<pii> adds[n+2],rems[n+2];
    for (int i=1;i<=k;i++) {
        int x1,y1,x2,y2;
        cin >> x1 >> y1 >> x2 >> y2;
        adds[x1].push_back({y1,y2});
        rems[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;
    vi p(n+1,0);
    for (int d : divs) {
        p[0] = 0;
        for (int i=1;i<=n;i++) {
            int val = (((i-1)/d)%2 == 0);
            p[i] = p[i-1]+val;
        }
        int sm = p[n];
        int need = 0;
        for (int j = 1;j<=n+1;j++) {
            for (auto it : adds[j]) {
                int old = p[it.ss]-p[it.ff-1];
                sm-=old;
                sm+=(it.ss-it.ff+1)-old;
            }
            for (auto it : rems[j]) {
                sm-=(it.ss-it.ff+1)-(p[it.ss]-p[it.ff-1]);
                sm+=p[it.ss]-p[it.ff-1];
            }
            if (j > n) break;
            if (((j-1)/d)%2 == 0) need+=sm;
            else need+=n-sm;
        }
        ans = min(ans,need);
        ans = min(ans,n*n-need);
    }
    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 508 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 564 KB Output is correct
8 Correct 1 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 25 ms 6992 KB Output is correct
2 Correct 7 ms 1872 KB Output is correct
3 Correct 21 ms 7088 KB Output is correct
4 Correct 12 ms 2896 KB Output is correct
5 Correct 23 ms 6216 KB Output is correct
6 Correct 15 ms 4804 KB Output is correct
7 Correct 4 ms 1872 KB Output is correct
8 Correct 15 ms 4944 KB Output is correct
9 Correct 33 ms 6472 KB Output is correct
10 Correct 25 ms 4960 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 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 520 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 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 520 KB Output is correct
16 Correct 7 ms 1872 KB Output is correct
17 Correct 20 ms 4688 KB Output is correct
18 Correct 23 ms 4704 KB Output is correct
19 Correct 32 ms 4936 KB Output is correct
20 Correct 27 ms 4792 KB Output is correct
21 Correct 19 ms 4688 KB Output is correct
22 Correct 1 ms 336 KB Output is correct
23 Correct 10 ms 2640 KB Output is correct
24 Correct 20 ms 4688 KB Output is correct
25 Correct 3 ms 824 KB Output is correct
26 Correct 15 ms 3152 KB Output is correct
27 Correct 20 ms 4176 KB Output is correct
28 Correct 27 ms 4936 KB Output is correct
29 Correct 9 ms 2128 KB Output is correct
30 Correct 1 ms 592 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 25 ms 6992 KB Output is correct
2 Correct 7 ms 1872 KB Output is correct
3 Correct 21 ms 7088 KB Output is correct
4 Correct 12 ms 2896 KB Output is correct
5 Correct 23 ms 6216 KB Output is correct
6 Correct 15 ms 4804 KB Output is correct
7 Correct 4 ms 1872 KB Output is correct
8 Correct 15 ms 4944 KB Output is correct
9 Correct 33 ms 6472 KB Output is correct
10 Correct 25 ms 4960 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 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 520 KB Output is correct
26 Correct 7 ms 1872 KB Output is correct
27 Correct 20 ms 4688 KB Output is correct
28 Correct 23 ms 4704 KB Output is correct
29 Correct 32 ms 4936 KB Output is correct
30 Correct 27 ms 4792 KB Output is correct
31 Correct 19 ms 4688 KB Output is correct
32 Correct 1 ms 336 KB Output is correct
33 Correct 10 ms 2640 KB Output is correct
34 Correct 20 ms 4688 KB Output is correct
35 Correct 3 ms 824 KB Output is correct
36 Correct 15 ms 3152 KB Output is correct
37 Correct 20 ms 4176 KB Output is correct
38 Correct 27 ms 4936 KB Output is correct
39 Correct 9 ms 2128 KB Output is correct
40 Correct 1 ms 592 KB Output is correct
41 Correct 66 ms 10312 KB Output is correct
42 Correct 45 ms 10824 KB Output is correct
43 Correct 51 ms 10688 KB Output is correct
44 Correct 61 ms 10624 KB Output is correct
45 Correct 44 ms 11424 KB Output is correct
46 Correct 68 ms 10824 KB Output is correct
47 Correct 42 ms 10312 KB Output is correct
48 Correct 48 ms 10568 KB Output is correct
49 Correct 39 ms 10332 KB Output is correct
50 Correct 215 ms 10316 KB Output is correct
51 Correct 225 ms 11592 KB Output is correct
52 Correct 221 ms 9764 KB Output is correct
53 Correct 217 ms 10064 KB Output is correct
54 Correct 211 ms 10824 KB Output is correct
55 Correct 249 ms 10148 KB Output is correct
56 Correct 222 ms 9800 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 1 ms 508 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 564 KB Output is correct
8 Correct 1 ms 348 KB Output is correct
9 Correct 25 ms 6992 KB Output is correct
10 Correct 7 ms 1872 KB Output is correct
11 Correct 21 ms 7088 KB Output is correct
12 Correct 12 ms 2896 KB Output is correct
13 Correct 23 ms 6216 KB Output is correct
14 Correct 15 ms 4804 KB Output is correct
15 Correct 4 ms 1872 KB Output is correct
16 Correct 15 ms 4944 KB Output is correct
17 Correct 33 ms 6472 KB Output is correct
18 Correct 25 ms 4960 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 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 520 KB Output is correct
34 Correct 7 ms 1872 KB Output is correct
35 Correct 20 ms 4688 KB Output is correct
36 Correct 23 ms 4704 KB Output is correct
37 Correct 32 ms 4936 KB Output is correct
38 Correct 27 ms 4792 KB Output is correct
39 Correct 19 ms 4688 KB Output is correct
40 Correct 1 ms 336 KB Output is correct
41 Correct 10 ms 2640 KB Output is correct
42 Correct 20 ms 4688 KB Output is correct
43 Correct 3 ms 824 KB Output is correct
44 Correct 15 ms 3152 KB Output is correct
45 Correct 20 ms 4176 KB Output is correct
46 Correct 27 ms 4936 KB Output is correct
47 Correct 9 ms 2128 KB Output is correct
48 Correct 1 ms 592 KB Output is correct
49 Correct 66 ms 10312 KB Output is correct
50 Correct 45 ms 10824 KB Output is correct
51 Correct 51 ms 10688 KB Output is correct
52 Correct 61 ms 10624 KB Output is correct
53 Correct 44 ms 11424 KB Output is correct
54 Correct 68 ms 10824 KB Output is correct
55 Correct 42 ms 10312 KB Output is correct
56 Correct 48 ms 10568 KB Output is correct
57 Correct 39 ms 10332 KB Output is correct
58 Correct 215 ms 10316 KB Output is correct
59 Correct 225 ms 11592 KB Output is correct
60 Correct 221 ms 9764 KB Output is correct
61 Correct 217 ms 10064 KB Output is correct
62 Correct 211 ms 10824 KB Output is correct
63 Correct 249 ms 10148 KB Output is correct
64 Correct 222 ms 9800 KB Output is correct
65 Correct 1 ms 336 KB Output is correct
66 Correct 1 ms 336 KB Output is correct
67 Correct 197 ms 10824 KB Output is correct
68 Correct 199 ms 9544 KB Output is correct
69 Correct 207 ms 10312 KB Output is correct
70 Correct 164 ms 10568 KB Output is correct
71 Correct 166 ms 9296 KB Output is correct
72 Correct 179 ms 9040 KB Output is correct
73 Correct 190 ms 10312 KB Output is correct
74 Correct 177 ms 9528 KB Output is correct
75 Correct 169 ms 10516 KB Output is correct
76 Correct 215 ms 10812 KB Output is correct
77 Correct 65 ms 12360 KB Output is correct
78 Correct 40 ms 10320 KB Output is correct
79 Correct 76 ms 11336 KB Output is correct
80 Correct 49 ms 10392 KB Output is correct
81 Correct 46 ms 10064 KB Output is correct
82 Correct 46 ms 10576 KB Output is correct
83 Correct 43 ms 11464 KB Output is correct
84 Correct 140 ms 11752 KB Output is correct
85 Correct 177 ms 9544 KB Output is correct
86 Correct 55 ms 4944 KB Output is correct
87 Correct 55 ms 4944 KB Output is correct
88 Correct 189 ms 9892 KB Output is correct
89 Correct 85 ms 6224 KB Output is correct
90 Correct 58 ms 4944 KB Output is correct