Submission #1112619

# Submission time Handle Problem Language Result Execution time Memory
1112619 2024-11-14T12:31:35 Z vjudge1 Chessboard (IZhO18_chessboard) C++17
100 / 100
224 ms 13128 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 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
# Verdict Execution time Memory Grader output
1 Correct 25 ms 6992 KB Output is correct
2 Correct 7 ms 1888 KB Output is correct
3 Correct 26 ms 7072 KB Output is correct
4 Correct 13 ms 2896 KB Output is correct
5 Correct 31 ms 6224 KB Output is correct
6 Correct 15 ms 4944 KB Output is correct
7 Correct 5 ms 1872 KB Output is correct
8 Correct 16 ms 4944 KB Output is correct
9 Correct 35 ms 6488 KB Output is correct
10 Correct 19 ms 5108 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 504 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 504 KB Output is correct
11 Correct 1 ms 336 KB Output is correct
12 Correct 1 ms 508 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 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 504 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 504 KB Output is correct
11 Correct 1 ms 336 KB Output is correct
12 Correct 1 ms 508 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 8 ms 1616 KB Output is correct
17 Correct 20 ms 4676 KB Output is correct
18 Correct 23 ms 4684 KB Output is correct
19 Correct 27 ms 4688 KB Output is correct
20 Correct 30 ms 4688 KB Output is correct
21 Correct 18 ms 4688 KB Output is correct
22 Correct 1 ms 336 KB Output is correct
23 Correct 12 ms 2640 KB Output is correct
24 Correct 29 ms 4780 KB Output is correct
25 Correct 3 ms 848 KB Output is correct
26 Correct 17 ms 3152 KB Output is correct
27 Correct 18 ms 4176 KB Output is correct
28 Correct 21 ms 4688 KB Output is correct
29 Correct 8 ms 2128 KB Output is correct
30 Correct 1 ms 760 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 25 ms 6992 KB Output is correct
2 Correct 7 ms 1888 KB Output is correct
3 Correct 26 ms 7072 KB Output is correct
4 Correct 13 ms 2896 KB Output is correct
5 Correct 31 ms 6224 KB Output is correct
6 Correct 15 ms 4944 KB Output is correct
7 Correct 5 ms 1872 KB Output is correct
8 Correct 16 ms 4944 KB Output is correct
9 Correct 35 ms 6488 KB Output is correct
10 Correct 19 ms 5108 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 504 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 504 KB Output is correct
21 Correct 1 ms 336 KB Output is correct
22 Correct 1 ms 508 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 8 ms 1616 KB Output is correct
27 Correct 20 ms 4676 KB Output is correct
28 Correct 23 ms 4684 KB Output is correct
29 Correct 27 ms 4688 KB Output is correct
30 Correct 30 ms 4688 KB Output is correct
31 Correct 18 ms 4688 KB Output is correct
32 Correct 1 ms 336 KB Output is correct
33 Correct 12 ms 2640 KB Output is correct
34 Correct 29 ms 4780 KB Output is correct
35 Correct 3 ms 848 KB Output is correct
36 Correct 17 ms 3152 KB Output is correct
37 Correct 18 ms 4176 KB Output is correct
38 Correct 21 ms 4688 KB Output is correct
39 Correct 8 ms 2128 KB Output is correct
40 Correct 1 ms 760 KB Output is correct
41 Correct 66 ms 10312 KB Output is correct
42 Correct 47 ms 10812 KB Output is correct
43 Correct 55 ms 10312 KB Output is correct
44 Correct 40 ms 10656 KB Output is correct
45 Correct 44 ms 11088 KB Output is correct
46 Correct 73 ms 10900 KB Output is correct
47 Correct 36 ms 10320 KB Output is correct
48 Correct 44 ms 10428 KB Output is correct
49 Correct 40 ms 10312 KB Output is correct
50 Correct 220 ms 9804 KB Output is correct
51 Correct 205 ms 12360 KB Output is correct
52 Correct 200 ms 12016 KB Output is correct
53 Correct 208 ms 12228 KB Output is correct
54 Correct 203 ms 11860 KB Output is correct
55 Correct 224 ms 12496 KB Output is correct
56 Correct 200 ms 11564 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 25 ms 6992 KB Output is correct
10 Correct 7 ms 1888 KB Output is correct
11 Correct 26 ms 7072 KB Output is correct
12 Correct 13 ms 2896 KB Output is correct
13 Correct 31 ms 6224 KB Output is correct
14 Correct 15 ms 4944 KB Output is correct
15 Correct 5 ms 1872 KB Output is correct
16 Correct 16 ms 4944 KB Output is correct
17 Correct 35 ms 6488 KB Output is correct
18 Correct 19 ms 5108 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 504 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 504 KB Output is correct
29 Correct 1 ms 336 KB Output is correct
30 Correct 1 ms 508 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 8 ms 1616 KB Output is correct
35 Correct 20 ms 4676 KB Output is correct
36 Correct 23 ms 4684 KB Output is correct
37 Correct 27 ms 4688 KB Output is correct
38 Correct 30 ms 4688 KB Output is correct
39 Correct 18 ms 4688 KB Output is correct
40 Correct 1 ms 336 KB Output is correct
41 Correct 12 ms 2640 KB Output is correct
42 Correct 29 ms 4780 KB Output is correct
43 Correct 3 ms 848 KB Output is correct
44 Correct 17 ms 3152 KB Output is correct
45 Correct 18 ms 4176 KB Output is correct
46 Correct 21 ms 4688 KB Output is correct
47 Correct 8 ms 2128 KB Output is correct
48 Correct 1 ms 760 KB Output is correct
49 Correct 66 ms 10312 KB Output is correct
50 Correct 47 ms 10812 KB Output is correct
51 Correct 55 ms 10312 KB Output is correct
52 Correct 40 ms 10656 KB Output is correct
53 Correct 44 ms 11088 KB Output is correct
54 Correct 73 ms 10900 KB Output is correct
55 Correct 36 ms 10320 KB Output is correct
56 Correct 44 ms 10428 KB Output is correct
57 Correct 40 ms 10312 KB Output is correct
58 Correct 220 ms 9804 KB Output is correct
59 Correct 205 ms 12360 KB Output is correct
60 Correct 200 ms 12016 KB Output is correct
61 Correct 208 ms 12228 KB Output is correct
62 Correct 203 ms 11860 KB Output is correct
63 Correct 224 ms 12496 KB Output is correct
64 Correct 200 ms 11564 KB Output is correct
65 Correct 1 ms 336 KB Output is correct
66 Correct 1 ms 336 KB Output is correct
67 Correct 192 ms 11896 KB Output is correct
68 Correct 194 ms 11636 KB Output is correct
69 Correct 174 ms 10824 KB Output is correct
70 Correct 172 ms 11396 KB Output is correct
71 Correct 181 ms 11228 KB Output is correct
72 Correct 176 ms 11344 KB Output is correct
73 Correct 200 ms 11272 KB Output is correct
74 Correct 186 ms 11592 KB Output is correct
75 Correct 185 ms 11368 KB Output is correct
76 Correct 207 ms 11948 KB Output is correct
77 Correct 64 ms 13128 KB Output is correct
78 Correct 45 ms 12516 KB Output is correct
79 Correct 52 ms 12224 KB Output is correct
80 Correct 50 ms 12368 KB Output is correct
81 Correct 56 ms 11848 KB Output is correct
82 Correct 56 ms 12628 KB Output is correct
83 Correct 48 ms 12104 KB Output is correct
84 Correct 134 ms 12952 KB Output is correct
85 Correct 192 ms 11848 KB Output is correct
86 Correct 55 ms 5116 KB Output is correct
87 Correct 54 ms 4944 KB Output is correct
88 Correct 207 ms 12104 KB Output is correct
89 Correct 87 ms 6224 KB Output is correct
90 Correct 54 ms 4944 KB Output is correct