답안 #368088

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
368088 2021-02-19T13:25:42 Z nicolaalexandra Chessboard (IZhO18_chessboard) C++14
100 / 100
879 ms 6548 KB
#include <bits/stdc++.h>

using namespace std;

long long n,k,i,x,y,x2,y2;
struct dreptunghi{
    long long x,y,x2,y2;
};
vector <dreptunghi> v;

long long count_(long long x, long long y, long long val){
    if (!x || !y)
        return 0;

    long long sol = 1LL * (x/val) * (y/val) / 2 * val * val;
    long long lastx = (x/val) * val, lasty = (y/val) * val;

    if (x/val % 2)
        sol +=  (y/val + 1)/2  * val * (x - lastx);
    else sol += (y/val/2) * val * (x - lastx);


    if (y/val % 2)
        sol += (x/val + 1)/2 * val * (y - lasty);
    else sol += (x/val/2) * val * (y - lasty);


    if (!(x/val % 2 == y/val%2))
        sol += (x - lastx) * (y - lasty);

    return sol;
}

long long solve (long long val){
    long long albe = 1LL * (n/val) * (n/val) / 2 * val * val; /// cate ar trebui sa fac albe daca e toata tabla neagra
    long long negre = 1LL * n * n - albe;

    for (auto it : v){
        long long x = it.x, y = it.y, x2 = it.x2, y2 = it.y2;

        long long cnt = count_(x2,y2,val) - count_(x2,y-1,val) - count_(x-1,y2,val) + count_(x-1,y-1,val);

        negre -= (x2-x+1) * (y2-y+1) - cnt; /// nu are sens sa le fac pe astea negre
        negre += cnt; /// trb sa le fac la loc  albe pe astea

        albe += (x2-x+1) * (y2-y+1) - cnt;
        albe -= cnt;
    }

    return min (albe,negre);
}

int main (){

    //ifstream cin ("date.in");
    //ofstream cout ("date.out");

    cin>>n>>k;
    for (i=1;i<=k;i++){
        cin>>x>>y>>x2>>y2;
        v.push_back({x,y,x2,y2});
    }

    long long sol = 1LL * n * n;
    for (long long d=1;d<n;d++){
        if (n % d == 0)
            sol = min (sol,solve(d));
    }

    cout<<sol;

    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 0 ms 364 KB Output is correct
4 Correct 0 ms 364 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
6 Correct 0 ms 364 KB Output is correct
7 Correct 0 ms 364 KB Output is correct
8 Correct 1 ms 364 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 79 ms 2528 KB Output is correct
2 Correct 20 ms 1508 KB Output is correct
3 Correct 51 ms 2528 KB Output is correct
4 Correct 51 ms 2528 KB Output is correct
5 Correct 69 ms 2528 KB Output is correct
6 Correct 46 ms 2528 KB Output is correct
7 Correct 9 ms 748 KB Output is correct
8 Correct 49 ms 2720 KB Output is correct
9 Correct 112 ms 4584 KB Output is correct
10 Correct 63 ms 2528 KB Output is correct
# 결과 실행 시간 메모리 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 2 ms 364 KB Output is correct
5 Correct 2 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 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 2 ms 364 KB Output is correct
14 Correct 2 ms 364 KB Output is correct
15 Correct 2 ms 364 KB Output is correct
# 결과 실행 시간 메모리 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 2 ms 364 KB Output is correct
5 Correct 2 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 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 2 ms 364 KB Output is correct
14 Correct 2 ms 364 KB Output is correct
15 Correct 2 ms 364 KB Output is correct
16 Correct 31 ms 1440 KB Output is correct
17 Correct 93 ms 4700 KB Output is correct
18 Correct 117 ms 4572 KB Output is correct
19 Correct 216 ms 4572 KB Output is correct
20 Correct 242 ms 4572 KB Output is correct
21 Correct 82 ms 4572 KB Output is correct
22 Correct 2 ms 364 KB Output is correct
23 Correct 58 ms 2660 KB Output is correct
24 Correct 103 ms 4572 KB Output is correct
25 Correct 15 ms 1000 KB Output is correct
26 Correct 63 ms 2528 KB Output is correct
27 Correct 85 ms 4572 KB Output is correct
28 Correct 107 ms 4572 KB Output is correct
29 Correct 34 ms 2676 KB Output is correct
30 Correct 4 ms 492 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 79 ms 2528 KB Output is correct
2 Correct 20 ms 1508 KB Output is correct
3 Correct 51 ms 2528 KB Output is correct
4 Correct 51 ms 2528 KB Output is correct
5 Correct 69 ms 2528 KB Output is correct
6 Correct 46 ms 2528 KB Output is correct
7 Correct 9 ms 748 KB Output is correct
8 Correct 49 ms 2720 KB Output is correct
9 Correct 112 ms 4584 KB Output is correct
10 Correct 63 ms 2528 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 2 ms 364 KB Output is correct
15 Correct 2 ms 364 KB Output is correct
16 Correct 1 ms 364 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 2 ms 364 KB Output is correct
24 Correct 2 ms 364 KB Output is correct
25 Correct 2 ms 364 KB Output is correct
26 Correct 31 ms 1440 KB Output is correct
27 Correct 93 ms 4700 KB Output is correct
28 Correct 117 ms 4572 KB Output is correct
29 Correct 216 ms 4572 KB Output is correct
30 Correct 242 ms 4572 KB Output is correct
31 Correct 82 ms 4572 KB Output is correct
32 Correct 2 ms 364 KB Output is correct
33 Correct 58 ms 2660 KB Output is correct
34 Correct 103 ms 4572 KB Output is correct
35 Correct 15 ms 1000 KB Output is correct
36 Correct 63 ms 2528 KB Output is correct
37 Correct 85 ms 4572 KB Output is correct
38 Correct 107 ms 4572 KB Output is correct
39 Correct 34 ms 2676 KB Output is correct
40 Correct 4 ms 492 KB Output is correct
41 Correct 214 ms 4572 KB Output is correct
42 Correct 133 ms 4572 KB Output is correct
43 Correct 164 ms 4572 KB Output is correct
44 Correct 128 ms 4572 KB Output is correct
45 Correct 126 ms 4576 KB Output is correct
46 Correct 242 ms 4572 KB Output is correct
47 Correct 112 ms 6364 KB Output is correct
48 Correct 154 ms 6428 KB Output is correct
49 Correct 118 ms 6364 KB Output is correct
50 Correct 791 ms 6536 KB Output is correct
51 Correct 838 ms 6364 KB Output is correct
52 Correct 777 ms 6364 KB Output is correct
53 Correct 838 ms 6536 KB Output is correct
54 Correct 784 ms 6492 KB Output is correct
55 Correct 871 ms 6364 KB Output is correct
56 Correct 756 ms 6364 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 0 ms 364 KB Output is correct
4 Correct 0 ms 364 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
6 Correct 0 ms 364 KB Output is correct
7 Correct 0 ms 364 KB Output is correct
8 Correct 1 ms 364 KB Output is correct
9 Correct 79 ms 2528 KB Output is correct
10 Correct 20 ms 1508 KB Output is correct
11 Correct 51 ms 2528 KB Output is correct
12 Correct 51 ms 2528 KB Output is correct
13 Correct 69 ms 2528 KB Output is correct
14 Correct 46 ms 2528 KB Output is correct
15 Correct 9 ms 748 KB Output is correct
16 Correct 49 ms 2720 KB Output is correct
17 Correct 112 ms 4584 KB Output is correct
18 Correct 63 ms 2528 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 2 ms 364 KB Output is correct
23 Correct 2 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 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 2 ms 364 KB Output is correct
32 Correct 2 ms 364 KB Output is correct
33 Correct 2 ms 364 KB Output is correct
34 Correct 31 ms 1440 KB Output is correct
35 Correct 93 ms 4700 KB Output is correct
36 Correct 117 ms 4572 KB Output is correct
37 Correct 216 ms 4572 KB Output is correct
38 Correct 242 ms 4572 KB Output is correct
39 Correct 82 ms 4572 KB Output is correct
40 Correct 2 ms 364 KB Output is correct
41 Correct 58 ms 2660 KB Output is correct
42 Correct 103 ms 4572 KB Output is correct
43 Correct 15 ms 1000 KB Output is correct
44 Correct 63 ms 2528 KB Output is correct
45 Correct 85 ms 4572 KB Output is correct
46 Correct 107 ms 4572 KB Output is correct
47 Correct 34 ms 2676 KB Output is correct
48 Correct 4 ms 492 KB Output is correct
49 Correct 214 ms 4572 KB Output is correct
50 Correct 133 ms 4572 KB Output is correct
51 Correct 164 ms 4572 KB Output is correct
52 Correct 128 ms 4572 KB Output is correct
53 Correct 126 ms 4576 KB Output is correct
54 Correct 242 ms 4572 KB Output is correct
55 Correct 112 ms 6364 KB Output is correct
56 Correct 154 ms 6428 KB Output is correct
57 Correct 118 ms 6364 KB Output is correct
58 Correct 791 ms 6536 KB Output is correct
59 Correct 838 ms 6364 KB Output is correct
60 Correct 777 ms 6364 KB Output is correct
61 Correct 838 ms 6536 KB Output is correct
62 Correct 784 ms 6492 KB Output is correct
63 Correct 871 ms 6364 KB Output is correct
64 Correct 756 ms 6364 KB Output is correct
65 Correct 1 ms 364 KB Output is correct
66 Correct 1 ms 364 KB Output is correct
67 Correct 814 ms 6492 KB Output is correct
68 Correct 836 ms 6548 KB Output is correct
69 Correct 717 ms 6364 KB Output is correct
70 Correct 803 ms 6364 KB Output is correct
71 Correct 799 ms 6492 KB Output is correct
72 Correct 780 ms 6364 KB Output is correct
73 Correct 753 ms 6372 KB Output is correct
74 Correct 806 ms 6364 KB Output is correct
75 Correct 782 ms 6364 KB Output is correct
76 Correct 840 ms 6344 KB Output is correct
77 Correct 209 ms 6364 KB Output is correct
78 Correct 125 ms 6236 KB Output is correct
79 Correct 161 ms 6364 KB Output is correct
80 Correct 169 ms 6380 KB Output is correct
81 Correct 161 ms 6364 KB Output is correct
82 Correct 156 ms 6364 KB Output is correct
83 Correct 144 ms 6364 KB Output is correct
84 Correct 526 ms 6492 KB Output is correct
85 Correct 857 ms 6208 KB Output is correct
86 Correct 2 ms 364 KB Output is correct
87 Correct 1 ms 364 KB Output is correct
88 Correct 879 ms 6364 KB Output is correct
89 Correct 168 ms 1892 KB Output is correct
90 Correct 1 ms 364 KB Output is correct