답안 #747096

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
747096 2023-05-23T15:47:23 Z heeheeheehaaw Chessboard (IZhO18_chessboard) C++17
70 / 100
444 ms 3448 KB
#include <iostream>
#include <vector>
#define int long long

using namespace std;

int a[1005][1005];
int spw[1005][1005], spb[1005][1005];
int x1[100005], x2[100005], y1[100005], y2[100005];

void add(int x, int y, int val, int &s1, int &s2)
{
    if((x + y) % 2 == 0)
        s1 += val;
    else
        s2 += val;
    return;
}

signed main()
{
    int s1 = 0, s2 = 0;
    int n, k;
    cin>>n>>k;

    vector<int> divs;
    for(int i = 1; i * i <= n; i++)
        if(n % i == 0)
        {
            divs.push_back(i);
            if(i * i != n && i != 1)
                divs.push_back(n / i);
        }

    for(int i = 1; i <= k; i++)
        cin>>x1[i]>>y1[i]>>x2[i]>>y2[i];

    int minn = n * n;
    for(auto d : divs)
    {
        int s1 = 0, s2 = 0;
        for(int i = 1; i <= k; i++)
        {
            int cx1 = (x1[i] - 1) / d + 1;
            int cy1 = (y1[i] - 1) / d + 1;
            int cx2 = (x2[i] - 1) / d + 1;
            int cy2 = (y2[i] - 1) / d + 1;

            if(cx1 == cx2 && cy1 == cy2)
            {
                int tt = (x2[i] - x1[i] + 1) * (y2[i] - y1[i] + 1);
                add(cx1, cy1, tt, s1, s2);
            }
            /*else if(cx1 == cx2 && cy1 != cy2)
            {
                /// colt stanga
                int tt = ((d * cy1) - y1[i] + 1) * (x2[i] - x1[i] + 1);
                add(cx1, cy1, tt, s1, s2);
                /// colt dreapta
                    tt = (y2[i] - d * (cy2 - 1)) * (x2[i] - x1[i] + 1);
                add(cx2, cy2, tt, s1, s2);
                /// mijloc
                if(cy2 - cy1 - 1 >= 1)
                {
                    int tt = d * (x2[i] - x1[i] + 1);
                    int np = cy2 - cy1 - 1;
                    int nri = np / 2, nrp = np / 2;
                    if(np % 2 == 1)
                        nri++;
                    add(cx1, cy1 + 1, tt * nri, s1, s2);
                    add(cx1, cy1 + 2, tt * nrp, s1, s2);
                }
            }*/
            else if(cx1 != cx2 && cy1 == cy2)
            {
                /// colt sus
                int tt = ((d * cx1) - x1[i] + 1) * (y2[i] - y1[i] + 1);
                add(cx1, cy1, tt, s1, s2);
                /// colt jos
                    tt = (x2[i] - d * (cx2 - 1)) * (y2[i] - y1[i] + 1);
                add(cx2, cy2, tt, s1, s2);
                /// mijloc
                if(cx2 - cx1 - 1 >= 1)
                {
                    int tt = d * (y2[i] - y1[i] + 1);
                    int np = cx2 - cx1 - 1;
                    int nri = np / 2, nrp = np / 2;
                    if(np % 2 == 1)
                        nri++;
                    add(cx1 + 1, cy1, tt * nri, s1, s2);
                    add(cx1 + 2, cy1, tt * nrp, s1, s2);
                }
            }
            else
            {
                /// colt st sus
                int tt = (d * cx1 - x1[i] + 1) * (d * cy1 - y1[i] + 1);
                add(cx1, cy1, tt, s1, s2);
                /// colt dr sus
                    tt = (d * cx1 - x1[i] + 1) * (y2[i] - d * (cy2 - 1));
                add(cx1, cy2, tt, s1, s2);
                /// colt st jos
                    tt = (x2[i] - d * (cx2 - 1)) * (d * cy1 - y1[i] + 1);
                add(cx2, cy1, tt, s1, s2);
                /// colt dr jos
                    tt = (x2[i] - d * (cx2 - 1)) * (y2[i] - d * (cy2 - 1));
                add(cx2, cy2, tt, s1, s2);
                /// marg sus si jos
                if(cy2 - cy1 - 1 >= 1)
                {
                    tt = (d * cx1 - x1[i] + 1) * d;
                    int np = cy2 - cy1 - 1;
                    int nri = np / 2, nrp = np / 2;
                    if(np % 2 == 1)
                        nri++;
                    add(cx1, cy1 + 1, tt * nri, s1, s2);
                    add(cx1, cy1 + 2, tt * nrp, s1, s2);
                    tt = (x2[i] - d * (cx2 - 1)) * d;
                    add(cx2, cy1 + 1, tt * nri, s1, s2);
                    add(cx2, cy1 + 2, tt * nrp, s1, s2);
                }
                /// marg st si dr
                if(cx2 - cx1 - 1 >= 1)
                {
                    tt = (d * cy1 - y1[i] + 1) * d;
                    int np = cx2 - cx1 - 1;
                    int nri = np / 2, nrp = np / 2;
                    if(np % 2 == 1)
                        nri++;
                    add(cx1 + 1, cy1, tt * nri, s1, s2);
                    add(cx1 + 2, cy1, tt * nrp, s1, s2);
                    tt = (y2[i] - d * (cy2 - 1)) * d;
                    add(cx1 + 1, cy2, tt * nri, s1, s2);
                    add(cx1 + 2, cy2, tt * nrp, s1, s2);
                }

                /// mijloc
                if((cx2 - cx1 - 1) * (cy2 - cy1 - 1) >= 1)
                {
                    int nrp = (cx2 - cx1 - 1) * (cy2 - cy1 - 1);
                    int d1 = nrp / 2, d2 = nrp / 2;
                    if(nrp % 2 == 1)
                        d1++;
                    add(cx1 + 1, cx2 + 1, d * d1, s1, s2);
                    add(cx1 + 1, cx2 + 2, d * d2, s1, s2);
                }
            }
        }

        int d1 = n * n, d2 = n * n;
        int nli = n / d / 2, nlp = n / d / 2;
        if((n / d) % 2 == 1) nli++;

        d2 -= (d * d * (nli * nli + nlp * nlp));
        d1 = n * n - d2;
        int ans = min(d1 - s1 + s2, d2 - s2 + s1);
        minn = min(minn, ans);
    }

    cout<<minn<<'\n';

    return 0;
}

Compilation message

chessboard.cpp: In function 'int main()':
chessboard.cpp:22:9: warning: unused variable 's1' [-Wunused-variable]
   22 |     int s1 = 0, s2 = 0;
      |         ^~
chessboard.cpp:22:17: warning: unused variable 's2' [-Wunused-variable]
   22 |     int s1 = 0, s2 = 0;
      |                 ^~
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 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 1 ms 212 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 69 ms 2236 KB Output is correct
2 Correct 17 ms 852 KB Output is correct
3 Correct 42 ms 1492 KB Output is correct
4 Correct 40 ms 1656 KB Output is correct
5 Correct 58 ms 1904 KB Output is correct
6 Correct 35 ms 1356 KB Output is correct
7 Correct 9 ms 452 KB Output is correct
8 Correct 43 ms 1364 KB Output is correct
9 Correct 90 ms 3076 KB Output is correct
10 Correct 54 ms 1868 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 2 ms 340 KB Output is correct
5 Correct 2 ms 340 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 1 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 340 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 2 ms 340 KB Output is correct
5 Correct 2 ms 340 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 1 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 340 KB Output is correct
16 Correct 22 ms 1108 KB Output is correct
17 Correct 71 ms 2892 KB Output is correct
18 Correct 86 ms 3368 KB Output is correct
19 Correct 135 ms 3064 KB Output is correct
20 Correct 138 ms 3368 KB Output is correct
21 Correct 67 ms 2788 KB Output is correct
22 Correct 1 ms 340 KB Output is correct
23 Correct 39 ms 1528 KB Output is correct
24 Correct 82 ms 3072 KB Output is correct
25 Correct 9 ms 596 KB Output is correct
26 Correct 53 ms 2000 KB Output is correct
27 Correct 76 ms 2424 KB Output is correct
28 Correct 84 ms 3248 KB Output is correct
29 Correct 31 ms 1340 KB Output is correct
30 Correct 3 ms 340 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 69 ms 2236 KB Output is correct
2 Correct 17 ms 852 KB Output is correct
3 Correct 42 ms 1492 KB Output is correct
4 Correct 40 ms 1656 KB Output is correct
5 Correct 58 ms 1904 KB Output is correct
6 Correct 35 ms 1356 KB Output is correct
7 Correct 9 ms 452 KB Output is correct
8 Correct 43 ms 1364 KB Output is correct
9 Correct 90 ms 3076 KB Output is correct
10 Correct 54 ms 1868 KB Output is correct
11 Correct 1 ms 340 KB Output is correct
12 Correct 0 ms 212 KB Output is correct
13 Correct 1 ms 340 KB Output is correct
14 Correct 2 ms 340 KB Output is correct
15 Correct 2 ms 340 KB Output is correct
16 Correct 1 ms 340 KB Output is correct
17 Correct 1 ms 340 KB Output is correct
18 Correct 1 ms 340 KB Output is correct
19 Correct 1 ms 340 KB Output is correct
20 Correct 1 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 340 KB Output is correct
26 Correct 22 ms 1108 KB Output is correct
27 Correct 71 ms 2892 KB Output is correct
28 Correct 86 ms 3368 KB Output is correct
29 Correct 135 ms 3064 KB Output is correct
30 Correct 138 ms 3368 KB Output is correct
31 Correct 67 ms 2788 KB Output is correct
32 Correct 1 ms 340 KB Output is correct
33 Correct 39 ms 1528 KB Output is correct
34 Correct 82 ms 3072 KB Output is correct
35 Correct 9 ms 596 KB Output is correct
36 Correct 53 ms 2000 KB Output is correct
37 Correct 76 ms 2424 KB Output is correct
38 Correct 84 ms 3248 KB Output is correct
39 Correct 31 ms 1340 KB Output is correct
40 Correct 3 ms 340 KB Output is correct
41 Correct 149 ms 2996 KB Output is correct
42 Correct 106 ms 3176 KB Output is correct
43 Correct 105 ms 2816 KB Output is correct
44 Correct 101 ms 3156 KB Output is correct
45 Correct 106 ms 3352 KB Output is correct
46 Correct 158 ms 3200 KB Output is correct
47 Correct 89 ms 2924 KB Output is correct
48 Correct 112 ms 3024 KB Output is correct
49 Correct 125 ms 2884 KB Output is correct
50 Correct 358 ms 3068 KB Output is correct
51 Correct 380 ms 3352 KB Output is correct
52 Correct 354 ms 3124 KB Output is correct
53 Correct 375 ms 3308 KB Output is correct
54 Correct 353 ms 3088 KB Output is correct
55 Correct 414 ms 3448 KB Output is correct
56 Correct 372 ms 2904 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 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 1 ms 212 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 69 ms 2236 KB Output is correct
10 Correct 17 ms 852 KB Output is correct
11 Correct 42 ms 1492 KB Output is correct
12 Correct 40 ms 1656 KB Output is correct
13 Correct 58 ms 1904 KB Output is correct
14 Correct 35 ms 1356 KB Output is correct
15 Correct 9 ms 452 KB Output is correct
16 Correct 43 ms 1364 KB Output is correct
17 Correct 90 ms 3076 KB Output is correct
18 Correct 54 ms 1868 KB Output is correct
19 Correct 1 ms 340 KB Output is correct
20 Correct 0 ms 212 KB Output is correct
21 Correct 1 ms 340 KB Output is correct
22 Correct 2 ms 340 KB Output is correct
23 Correct 2 ms 340 KB Output is correct
24 Correct 1 ms 340 KB Output is correct
25 Correct 1 ms 340 KB Output is correct
26 Correct 1 ms 340 KB Output is correct
27 Correct 1 ms 340 KB Output is correct
28 Correct 1 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 340 KB Output is correct
34 Correct 22 ms 1108 KB Output is correct
35 Correct 71 ms 2892 KB Output is correct
36 Correct 86 ms 3368 KB Output is correct
37 Correct 135 ms 3064 KB Output is correct
38 Correct 138 ms 3368 KB Output is correct
39 Correct 67 ms 2788 KB Output is correct
40 Correct 1 ms 340 KB Output is correct
41 Correct 39 ms 1528 KB Output is correct
42 Correct 82 ms 3072 KB Output is correct
43 Correct 9 ms 596 KB Output is correct
44 Correct 53 ms 2000 KB Output is correct
45 Correct 76 ms 2424 KB Output is correct
46 Correct 84 ms 3248 KB Output is correct
47 Correct 31 ms 1340 KB Output is correct
48 Correct 3 ms 340 KB Output is correct
49 Correct 149 ms 2996 KB Output is correct
50 Correct 106 ms 3176 KB Output is correct
51 Correct 105 ms 2816 KB Output is correct
52 Correct 101 ms 3156 KB Output is correct
53 Correct 106 ms 3352 KB Output is correct
54 Correct 158 ms 3200 KB Output is correct
55 Correct 89 ms 2924 KB Output is correct
56 Correct 112 ms 3024 KB Output is correct
57 Correct 125 ms 2884 KB Output is correct
58 Correct 358 ms 3068 KB Output is correct
59 Correct 380 ms 3352 KB Output is correct
60 Correct 354 ms 3124 KB Output is correct
61 Correct 375 ms 3308 KB Output is correct
62 Correct 353 ms 3088 KB Output is correct
63 Correct 414 ms 3448 KB Output is correct
64 Correct 372 ms 2904 KB Output is correct
65 Correct 1 ms 340 KB Output is correct
66 Correct 0 ms 212 KB Output is correct
67 Incorrect 444 ms 3288 KB Output isn't correct
68 Halted 0 ms 0 KB -