Submission #336151

# Submission time Handle Problem Language Result Execution time Memory
336151 2020-12-14T22:38:09 Z mat_v Chessboard (IZhO18_chessboard) C++14
47 / 100
126 ms 5276 KB
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/rope>

#define ff(i,a,b) for(int (i) = (a); (i) <= (b); ++(i))
#define fb(i,a,b) for(int (i) = (a); (i) >= (b); --(i))
#define mod 998244353
#define xx firsts
#define yy second
#define all(a) (a).begin(), (a).end()
#define pb push_back
#define ll long long
#define pii pair<int,int>
#define maxn 100005


using namespace std;
using namespace __gnu_pbds;
typedef tree<int, null_type, less<int>,rb_tree_tag, tree_order_statistics_node_update> ordered_set;/// find_by_order(x)(x+1th) , order_of_key() (strictly less)
mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count());


int n;
int m;

struct kv{
    ll x1;
    ll y1;
    ll x2;
    ll y2;
}niz[maxn];

ll get(ll l, ll r, ll broj){
    if(l > r)return 0;
    ll prvi = (l/broj)*broj;
    if(l != prvi)prvi += broj;
    ll last = (r/broj)*broj;
    if(prvi > r){
        if((l%broj) < broj/2){
            return min((broj/2)-1, (r%broj))-(l%broj)+1;
        }
        return 0;
    }
    ll klk = last/broj - prvi/broj;
    return (klk)*(broj/2) + get(l,prvi-1,broj) + get(last+1,r,broj)+1;
}

int main()
{

    ios_base::sync_with_stdio(false); cin.tie(0);

    cin >> n >> m;
    ff(i,1,m){
        int a,b,c,d;
        cin >> a >> b >> c >> d;
        a--; b--; c--; d--;
        niz[i] = {a,b,c,d};
    }
    ll ans = 1e9;
    ans *= 10;
    ff(i,1,n - 1){
        if(n%i != 0)continue;
        ll b = 0;
        ll w = 0;
        ll tr = 2*i;
        ff(j,1,m){
            ll uk = 0;
            ll blackrow = get(niz[j].x1,niz[j].x2,tr);
            ll blackcol = get(niz[j].y1,niz[j].y2,tr);
            uk += (blackrow*blackcol);
            blackrow = niz[j].x2 - niz[j].x1 + 1 - blackrow;
            blackcol = niz[j].y2 - niz[j].y1 + 1 - blackcol;
            uk += (blackrow*blackcol);
            b += uk;
            w += ((niz[j].x2 - niz[j].x1 + 1) * (niz[j].y2 - niz[j].y1 + 1) - uk);
        }
        ll str = (n/i);
        ll p1 = (str*str + 1) / 2;
        ll p2 = (str*str) / 2;
        p1 *= (i*i);
        p2 *= (i*i);
        ll tmp = min(p1 - b + w, p2 - w + b);
        //cout << i << " " << tmp << "\n";
        ans = min(ans, tmp);
    }
    cout << ans << "\n";
    return 0;
}
/*
6 8
3 3 3 3
1 2 1 2
3 4 3 4
5 5 5 5
4 3 4 3
4 4 4 4
2 1 2 1
3 6 3 6
*/

Compilation message

chessboard.cpp: In function 'int main()':
chessboard.cpp:6:27: warning: unnecessary parentheses in declaration of 'i' [-Wparentheses]
    6 | #define ff(i,a,b) for(int (i) = (a); (i) <= (b); ++(i))
      |                           ^
chessboard.cpp:55:5: note: in expansion of macro 'ff'
   55 |     ff(i,1,m){
      |     ^~
chessboard.cpp:6:27: warning: unnecessary parentheses in declaration of 'i' [-Wparentheses]
    6 | #define ff(i,a,b) for(int (i) = (a); (i) <= (b); ++(i))
      |                           ^
chessboard.cpp:63:5: note: in expansion of macro 'ff'
   63 |     ff(i,1,n - 1){
      |     ^~
chessboard.cpp:6:27: warning: unnecessary parentheses in declaration of 'j' [-Wparentheses]
    6 | #define ff(i,a,b) for(int (i) = (a); (i) <= (b); ++(i))
      |                           ^
chessboard.cpp:68:9: note: in expansion of macro 'ff'
   68 |         ff(j,1,m){
      |         ^~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
6 Correct 1 ms 364 KB Output is correct
7 Correct 1 ms 364 KB Output is correct
8 Correct 1 ms 364 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 27 ms 3820 KB Output is correct
2 Correct 8 ms 1260 KB Output is correct
3 Correct 17 ms 2540 KB Output is correct
4 Correct 19 ms 2668 KB Output is correct
5 Correct 25 ms 3308 KB Output is correct
6 Correct 16 ms 2304 KB Output is correct
7 Correct 4 ms 768 KB Output is correct
8 Correct 16 ms 2212 KB Output is correct
9 Correct 43 ms 5276 KB Output is correct
10 Correct 22 ms 3072 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 1 ms 384 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
6 Correct 1 ms 372 KB Output is correct
7 Correct 1 ms 364 KB Output is correct
8 Correct 1 ms 364 KB Output is correct
9 Correct 1 ms 364 KB Output is correct
10 Correct 1 ms 364 KB Output is correct
11 Correct 1 ms 364 KB Output is correct
12 Correct 1 ms 384 KB Output is correct
13 Correct 1 ms 364 KB Output is correct
14 Correct 1 ms 364 KB Output is correct
15 Correct 1 ms 364 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 1 ms 384 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
6 Correct 1 ms 372 KB Output is correct
7 Correct 1 ms 364 KB Output is correct
8 Correct 1 ms 364 KB Output is correct
9 Correct 1 ms 364 KB Output is correct
10 Correct 1 ms 364 KB Output is correct
11 Correct 1 ms 364 KB Output is correct
12 Correct 1 ms 384 KB Output is correct
13 Correct 1 ms 364 KB Output is correct
14 Correct 1 ms 364 KB Output is correct
15 Correct 1 ms 364 KB Output is correct
16 Correct 13 ms 1644 KB Output is correct
17 Correct 31 ms 4352 KB Output is correct
18 Correct 43 ms 5100 KB Output is correct
19 Correct 109 ms 4588 KB Output is correct
20 Correct 126 ms 5100 KB Output is correct
21 Correct 30 ms 4204 KB Output is correct
22 Correct 1 ms 364 KB Output is correct
23 Correct 25 ms 2412 KB Output is correct
24 Correct 39 ms 4588 KB Output is correct
25 Correct 5 ms 748 KB Output is correct
26 Correct 25 ms 3052 KB Output is correct
27 Correct 35 ms 3564 KB Output is correct
28 Correct 42 ms 4844 KB Output is correct
29 Correct 13 ms 1900 KB Output is correct
30 Correct 2 ms 492 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 27 ms 3820 KB Output is correct
2 Correct 8 ms 1260 KB Output is correct
3 Correct 17 ms 2540 KB Output is correct
4 Correct 19 ms 2668 KB Output is correct
5 Correct 25 ms 3308 KB Output is correct
6 Correct 16 ms 2304 KB Output is correct
7 Correct 4 ms 768 KB Output is correct
8 Correct 16 ms 2212 KB Output is correct
9 Correct 43 ms 5276 KB Output is correct
10 Correct 22 ms 3072 KB Output is correct
11 Correct 1 ms 364 KB Output is correct
12 Correct 1 ms 364 KB Output is correct
13 Correct 1 ms 364 KB Output is correct
14 Correct 1 ms 384 KB Output is correct
15 Correct 1 ms 364 KB Output is correct
16 Correct 1 ms 372 KB Output is correct
17 Correct 1 ms 364 KB Output is correct
18 Correct 1 ms 364 KB Output is correct
19 Correct 1 ms 364 KB Output is correct
20 Correct 1 ms 364 KB Output is correct
21 Correct 1 ms 364 KB Output is correct
22 Correct 1 ms 384 KB Output is correct
23 Correct 1 ms 364 KB Output is correct
24 Correct 1 ms 364 KB Output is correct
25 Correct 1 ms 364 KB Output is correct
26 Correct 13 ms 1644 KB Output is correct
27 Correct 31 ms 4352 KB Output is correct
28 Correct 43 ms 5100 KB Output is correct
29 Correct 109 ms 4588 KB Output is correct
30 Correct 126 ms 5100 KB Output is correct
31 Correct 30 ms 4204 KB Output is correct
32 Correct 1 ms 364 KB Output is correct
33 Correct 25 ms 2412 KB Output is correct
34 Correct 39 ms 4588 KB Output is correct
35 Correct 5 ms 748 KB Output is correct
36 Correct 25 ms 3052 KB Output is correct
37 Correct 35 ms 3564 KB Output is correct
38 Correct 42 ms 4844 KB Output is correct
39 Correct 13 ms 1900 KB Output is correct
40 Correct 2 ms 492 KB Output is correct
41 Incorrect 100 ms 4972 KB Output isn't correct
42 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
6 Correct 1 ms 364 KB Output is correct
7 Correct 1 ms 364 KB Output is correct
8 Correct 1 ms 364 KB Output is correct
9 Correct 27 ms 3820 KB Output is correct
10 Correct 8 ms 1260 KB Output is correct
11 Correct 17 ms 2540 KB Output is correct
12 Correct 19 ms 2668 KB Output is correct
13 Correct 25 ms 3308 KB Output is correct
14 Correct 16 ms 2304 KB Output is correct
15 Correct 4 ms 768 KB Output is correct
16 Correct 16 ms 2212 KB Output is correct
17 Correct 43 ms 5276 KB Output is correct
18 Correct 22 ms 3072 KB Output is correct
19 Correct 1 ms 364 KB Output is correct
20 Correct 1 ms 364 KB Output is correct
21 Correct 1 ms 364 KB Output is correct
22 Correct 1 ms 384 KB Output is correct
23 Correct 1 ms 364 KB Output is correct
24 Correct 1 ms 372 KB Output is correct
25 Correct 1 ms 364 KB Output is correct
26 Correct 1 ms 364 KB Output is correct
27 Correct 1 ms 364 KB Output is correct
28 Correct 1 ms 364 KB Output is correct
29 Correct 1 ms 364 KB Output is correct
30 Correct 1 ms 384 KB Output is correct
31 Correct 1 ms 364 KB Output is correct
32 Correct 1 ms 364 KB Output is correct
33 Correct 1 ms 364 KB Output is correct
34 Correct 13 ms 1644 KB Output is correct
35 Correct 31 ms 4352 KB Output is correct
36 Correct 43 ms 5100 KB Output is correct
37 Correct 109 ms 4588 KB Output is correct
38 Correct 126 ms 5100 KB Output is correct
39 Correct 30 ms 4204 KB Output is correct
40 Correct 1 ms 364 KB Output is correct
41 Correct 25 ms 2412 KB Output is correct
42 Correct 39 ms 4588 KB Output is correct
43 Correct 5 ms 748 KB Output is correct
44 Correct 25 ms 3052 KB Output is correct
45 Correct 35 ms 3564 KB Output is correct
46 Correct 42 ms 4844 KB Output is correct
47 Correct 13 ms 1900 KB Output is correct
48 Correct 2 ms 492 KB Output is correct
49 Incorrect 100 ms 4972 KB Output isn't correct
50 Halted 0 ms 0 KB -