Submission #779263

# Submission time Handle Problem Language Result Execution time Memory
779263 2023-07-11T09:39:59 Z teamariaa Chessboard (IZhO18_chessboard) C++17
70 / 100
254 ms 3536 KB
#include <bits/stdc++.h>

using namespace std;

#define pb push_back

long long n, k;
long long ans = LLONG_MAX;
struct square
{
    int x, y;
};
vector <square> squares;

void solve(int squareSize)
{
    long long idk = (n / squareSize), idk2;
//    cout << squareSize << "\n";
    if(idk % 2)
        idk2 = idk * (idk / 2) + (idk + 1) / 2;
    else
        idk2 = idk * idk / 2;
//    cout << idk << "\n";
    long long cnt1 = 1ll * squareSize * squareSize * idk2, cnt2 = 1ll * n * n - cnt1;
//    cout << cnt1 << " " << cnt2 << "\n";
    for(auto x : squares)
    {
        long long r1, c1, r2, c2, a, b;
        c1 = x.x / squareSize;
        r1 = x.x % squareSize;

        if(r1)
            c1 ++;
        a = c1 % 2;

        c2 = x.y / squareSize;
        r2 = x.y % squareSize;

        if(r2)
            c2 ++;
        b = c2 % 2;

        /// incepem cu alb
        if(a == 1  &&  b == 0)
        {
//            cout << x.x << " " << x.y << "patrat negru\n";
            cnt2 --;
        }
        else if(a == 1  &&  b == 1)
        {
//            cout << x.x << " " << x.y << "patrat alb\n";
            // patrat alb
            cnt2 ++;

        }
        else if(a == 0  &&  b == 0)
        {
//            cout << x.x << " " << x.y << "patrat alb\n";
            // patrat alb
            cnt2 ++;
        }
        else
        {
//            cout << x.x << " " << x.y << "patrat negru\n";
            // patrat negru
            cnt2 --;
        }

        /// acum negru
        if(a == 1  &&  b == 0)
        {
//            cout << x.x << " " << x.y << "patrat alb\n";
            // patrat alb
            cnt1 ++;
        }
        else if(a == 1  &&  b == 1)
        {
//            cout << x.x << " " << x.y << "patrat negru\n";
            // patrat negru
            cnt1 --;
        }
        else if(a == 0  &&  b == 0)
        {
//            cout << x.x << " " << x.y << "patrat negru\n";
            // patrat negru
            cnt1 --;
        }
        else
        {
//            cout << x.x << " " << x.y << "patrat alb\n";
            // patrat alb
            cnt1 ++;
        }
    }
    ans = min(ans, min(cnt1, cnt2));
//    cout << cnt1 << " " << cnt2 << "\n\n";
}

int main()
{
    ios_base :: sync_with_stdio(0);
    cin.tie(0);

    //freopen(".in", "r", stdin);
    //freopen(".out", "w", stdout);

    cin >> n >> k;
    for(int i = 1; i <= k; i ++)
    {
        int x1, y1, x2, y2;
        cin >> x1 >> y1 >> x2 >> y2;
        squares.pb({x1, y1});
    }

    long long d = 1;
    while(d * d <= n)
    {
        if(n % d == 0)
        {
            solve(d);
            if(d != 1  &&  d * d != n)
                solve(n / d);
        }
        d ++;
    }

    cout << ans;
    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 320 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 15 ms 984 KB Output is correct
2 Correct 5 ms 1040 KB Output is correct
3 Correct 11 ms 1880 KB Output is correct
4 Correct 12 ms 1752 KB Output is correct
5 Correct 14 ms 2096 KB Output is correct
6 Correct 10 ms 1740 KB Output is correct
7 Correct 2 ms 596 KB Output is correct
8 Correct 15 ms 1684 KB Output is correct
9 Correct 30 ms 3176 KB Output is correct
10 Correct 13 ms 1972 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 0 ms 340 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
10 Correct 0 ms 212 KB Output is correct
11 Correct 1 ms 340 KB Output is correct
12 Correct 1 ms 340 KB Output is correct
13 Correct 1 ms 340 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
15 Correct 1 ms 328 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 0 ms 340 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
10 Correct 0 ms 212 KB Output is correct
11 Correct 1 ms 340 KB Output is correct
12 Correct 1 ms 340 KB Output is correct
13 Correct 1 ms 340 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
15 Correct 1 ms 328 KB Output is correct
16 Correct 7 ms 1108 KB Output is correct
17 Correct 28 ms 2640 KB Output is correct
18 Correct 33 ms 2736 KB Output is correct
19 Correct 57 ms 2656 KB Output is correct
20 Correct 65 ms 2776 KB Output is correct
21 Correct 23 ms 2744 KB Output is correct
22 Correct 1 ms 212 KB Output is correct
23 Correct 14 ms 1652 KB Output is correct
24 Correct 22 ms 2732 KB Output is correct
25 Correct 3 ms 596 KB Output is correct
26 Correct 15 ms 1768 KB Output is correct
27 Correct 19 ms 2460 KB Output is correct
28 Correct 24 ms 2672 KB Output is correct
29 Correct 8 ms 1488 KB Output is correct
30 Correct 1 ms 340 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 15 ms 984 KB Output is correct
2 Correct 5 ms 1040 KB Output is correct
3 Correct 11 ms 1880 KB Output is correct
4 Correct 12 ms 1752 KB Output is correct
5 Correct 14 ms 2096 KB Output is correct
6 Correct 10 ms 1740 KB Output is correct
7 Correct 2 ms 596 KB Output is correct
8 Correct 15 ms 1684 KB Output is correct
9 Correct 30 ms 3176 KB Output is correct
10 Correct 13 ms 1972 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Correct 0 ms 212 KB Output is correct
13 Correct 1 ms 212 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
15 Correct 1 ms 212 KB Output is correct
16 Correct 1 ms 212 KB Output is correct
17 Correct 1 ms 340 KB Output is correct
18 Correct 0 ms 340 KB Output is correct
19 Correct 0 ms 212 KB Output is correct
20 Correct 0 ms 212 KB Output is correct
21 Correct 1 ms 340 KB Output is correct
22 Correct 1 ms 340 KB Output is correct
23 Correct 1 ms 340 KB Output is correct
24 Correct 1 ms 340 KB Output is correct
25 Correct 1 ms 328 KB Output is correct
26 Correct 7 ms 1108 KB Output is correct
27 Correct 28 ms 2640 KB Output is correct
28 Correct 33 ms 2736 KB Output is correct
29 Correct 57 ms 2656 KB Output is correct
30 Correct 65 ms 2776 KB Output is correct
31 Correct 23 ms 2744 KB Output is correct
32 Correct 1 ms 212 KB Output is correct
33 Correct 14 ms 1652 KB Output is correct
34 Correct 22 ms 2732 KB Output is correct
35 Correct 3 ms 596 KB Output is correct
36 Correct 15 ms 1768 KB Output is correct
37 Correct 19 ms 2460 KB Output is correct
38 Correct 24 ms 2672 KB Output is correct
39 Correct 8 ms 1488 KB Output is correct
40 Correct 1 ms 340 KB Output is correct
41 Correct 54 ms 3240 KB Output is correct
42 Correct 27 ms 3400 KB Output is correct
43 Correct 36 ms 3248 KB Output is correct
44 Correct 26 ms 3268 KB Output is correct
45 Correct 25 ms 3536 KB Output is correct
46 Correct 68 ms 3360 KB Output is correct
47 Correct 22 ms 3156 KB Output is correct
48 Correct 38 ms 3232 KB Output is correct
49 Correct 25 ms 3232 KB Output is correct
50 Correct 226 ms 3284 KB Output is correct
51 Correct 242 ms 3408 KB Output is correct
52 Correct 230 ms 3268 KB Output is correct
53 Correct 241 ms 3408 KB Output is correct
54 Correct 222 ms 3288 KB Output is correct
55 Correct 254 ms 3520 KB Output is correct
56 Correct 216 ms 3244 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 320 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 15 ms 984 KB Output is correct
10 Correct 5 ms 1040 KB Output is correct
11 Correct 11 ms 1880 KB Output is correct
12 Correct 12 ms 1752 KB Output is correct
13 Correct 14 ms 2096 KB Output is correct
14 Correct 10 ms 1740 KB Output is correct
15 Correct 2 ms 596 KB Output is correct
16 Correct 15 ms 1684 KB Output is correct
17 Correct 30 ms 3176 KB Output is correct
18 Correct 13 ms 1972 KB Output is correct
19 Correct 1 ms 212 KB Output is correct
20 Correct 0 ms 212 KB Output is correct
21 Correct 1 ms 212 KB Output is correct
22 Correct 1 ms 340 KB Output is correct
23 Correct 1 ms 212 KB Output is correct
24 Correct 1 ms 212 KB Output is correct
25 Correct 1 ms 340 KB Output is correct
26 Correct 0 ms 340 KB Output is correct
27 Correct 0 ms 212 KB Output is correct
28 Correct 0 ms 212 KB Output is correct
29 Correct 1 ms 340 KB Output is correct
30 Correct 1 ms 340 KB Output is correct
31 Correct 1 ms 340 KB Output is correct
32 Correct 1 ms 340 KB Output is correct
33 Correct 1 ms 328 KB Output is correct
34 Correct 7 ms 1108 KB Output is correct
35 Correct 28 ms 2640 KB Output is correct
36 Correct 33 ms 2736 KB Output is correct
37 Correct 57 ms 2656 KB Output is correct
38 Correct 65 ms 2776 KB Output is correct
39 Correct 23 ms 2744 KB Output is correct
40 Correct 1 ms 212 KB Output is correct
41 Correct 14 ms 1652 KB Output is correct
42 Correct 22 ms 2732 KB Output is correct
43 Correct 3 ms 596 KB Output is correct
44 Correct 15 ms 1768 KB Output is correct
45 Correct 19 ms 2460 KB Output is correct
46 Correct 24 ms 2672 KB Output is correct
47 Correct 8 ms 1488 KB Output is correct
48 Correct 1 ms 340 KB Output is correct
49 Correct 54 ms 3240 KB Output is correct
50 Correct 27 ms 3400 KB Output is correct
51 Correct 36 ms 3248 KB Output is correct
52 Correct 26 ms 3268 KB Output is correct
53 Correct 25 ms 3536 KB Output is correct
54 Correct 68 ms 3360 KB Output is correct
55 Correct 22 ms 3156 KB Output is correct
56 Correct 38 ms 3232 KB Output is correct
57 Correct 25 ms 3232 KB Output is correct
58 Correct 226 ms 3284 KB Output is correct
59 Correct 242 ms 3408 KB Output is correct
60 Correct 230 ms 3268 KB Output is correct
61 Correct 241 ms 3408 KB Output is correct
62 Correct 222 ms 3288 KB Output is correct
63 Correct 254 ms 3520 KB Output is correct
64 Correct 216 ms 3244 KB Output is correct
65 Correct 1 ms 212 KB Output is correct
66 Incorrect 0 ms 212 KB Output isn't correct
67 Halted 0 ms 0 KB -