Submission #747059

# Submission time Handle Problem Language Result Execution time Memory
747059 2023-05-23T14:21:11 Z heeheeheehaaw Chessboard (IZhO18_chessboard) C++17
47 / 100
111 ms 23828 KB
#include <iostream>
#include <vector>
#define int long long

using namespace std;

int a[1005][1005];
int spw[1005][1005], spb[1005][1005];

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

    for(int i = 1; i <= k; i++)
    {
        int x1, y1, x2, y2;
        cin>>x1>>y1>>x2>>y2;
        if(n <= 1000)
            a[x1][y1] = 1;
        else
        {
            if((x1 + y1) % 2 == 0)
                s1++;
            else
                s2++;
        }
    }

    if(n > 1000)
    {
        int d1 = n * n / 2, d2 = n * n / 2;
        if(n % 2 == 1)
            d1++;
        int ans = min(d1 - s1 + s2, d2 - s2 + s1);
        cout<<ans<<'\n';
        return 0;
    }

    for(int i = 1; i <= n; i++)
        for(int j = 1; j <= n; j++)
        {
            if(a[i][j] == 0) spw[i][j]++;
            else spb[i][j]++;
            spw[i][j] += spw[i][j - 1] + spw[i - 1][j] - spw[i - 1][j - 1];
            spb[i][j] += spb[i][j - 1] + spb[i - 1][j] - spb[i - 1][j - 1];
        }

    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);
        }

    int minn = n * n;
    for(auto d : divs)
    {
        for(int pas = 0; pas <= 1; pas++)
        {
            int col = pas, sum = 0;
            for(int i = d; i <= n; i += d)
            {
                if((i / d) % 2 == 0)
                    col = pas;
                else
                    col = 1 - pas;
                for(int j = d; j <= n; j += d)
                {
                    if(col == 0)
                        sum += spb[i][j] - spb[i - d][j] - spb[i][j - d] + spb[i - d][j - d];
                    else
                        sum += spw[i][j] - spw[i - d][j] - spw[i][j - d] + spw[i - d][j - d];
                    col = 1 - col;
                }
            }

            minn = min(minn, sum);
        }
    }

    cout<<minn<<'\n';

    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 ms 1364 KB Output is correct
3 Correct 1 ms 1236 KB Output is correct
4 Correct 1 ms 1236 KB Output is correct
5 Correct 1 ms 1236 KB Output is correct
6 Correct 1 ms 1236 KB Output is correct
7 Correct 1 ms 1236 KB Output is correct
8 Correct 1 ms 1108 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 64 ms 288 KB Output is correct
2 Correct 18 ms 596 KB Output is correct
3 Correct 41 ms 1304 KB Output is correct
4 Correct 45 ms 1152 KB Output is correct
5 Correct 59 ms 1560 KB Output is correct
6 Correct 36 ms 1052 KB Output is correct
7 Correct 8 ms 468 KB Output is correct
8 Correct 36 ms 1052 KB Output is correct
9 Correct 92 ms 2324 KB Output is correct
10 Correct 56 ms 1424 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 1364 KB Output is correct
2 Correct 1 ms 980 KB Output is correct
3 Correct 1 ms 1236 KB Output is correct
4 Correct 2 ms 1364 KB Output is correct
5 Correct 1 ms 1364 KB Output is correct
6 Correct 1 ms 1236 KB Output is correct
7 Correct 1 ms 1492 KB Output is correct
8 Correct 1 ms 1108 KB Output is correct
9 Correct 1 ms 1620 KB Output is correct
10 Correct 1 ms 1108 KB Output is correct
11 Correct 1 ms 1108 KB Output is correct
12 Correct 1 ms 980 KB Output is correct
13 Correct 2 ms 1108 KB Output is correct
14 Correct 1 ms 1236 KB Output is correct
15 Correct 2 ms 980 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 1364 KB Output is correct
2 Correct 1 ms 980 KB Output is correct
3 Correct 1 ms 1236 KB Output is correct
4 Correct 2 ms 1364 KB Output is correct
5 Correct 1 ms 1364 KB Output is correct
6 Correct 1 ms 1236 KB Output is correct
7 Correct 1 ms 1492 KB Output is correct
8 Correct 1 ms 1108 KB Output is correct
9 Correct 1 ms 1620 KB Output is correct
10 Correct 1 ms 1108 KB Output is correct
11 Correct 1 ms 1108 KB Output is correct
12 Correct 1 ms 980 KB Output is correct
13 Correct 2 ms 1108 KB Output is correct
14 Correct 1 ms 1236 KB Output is correct
15 Correct 2 ms 980 KB Output is correct
16 Correct 45 ms 22692 KB Output is correct
17 Correct 94 ms 23756 KB Output is correct
18 Correct 108 ms 23732 KB Output is correct
19 Correct 96 ms 22864 KB Output is correct
20 Correct 111 ms 22952 KB Output is correct
21 Correct 100 ms 23792 KB Output is correct
22 Correct 19 ms 17576 KB Output is correct
23 Correct 62 ms 23140 KB Output is correct
24 Correct 98 ms 23828 KB Output is correct
25 Correct 25 ms 23024 KB Output is correct
26 Correct 65 ms 22808 KB Output is correct
27 Correct 71 ms 22988 KB Output is correct
28 Correct 96 ms 22808 KB Output is correct
29 Correct 44 ms 23088 KB Output is correct
30 Correct 21 ms 21544 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 64 ms 288 KB Output is correct
2 Correct 18 ms 596 KB Output is correct
3 Correct 41 ms 1304 KB Output is correct
4 Correct 45 ms 1152 KB Output is correct
5 Correct 59 ms 1560 KB Output is correct
6 Correct 36 ms 1052 KB Output is correct
7 Correct 8 ms 468 KB Output is correct
8 Correct 36 ms 1052 KB Output is correct
9 Correct 92 ms 2324 KB Output is correct
10 Correct 56 ms 1424 KB Output is correct
11 Correct 2 ms 1364 KB Output is correct
12 Correct 1 ms 980 KB Output is correct
13 Correct 1 ms 1236 KB Output is correct
14 Correct 2 ms 1364 KB Output is correct
15 Correct 1 ms 1364 KB Output is correct
16 Correct 1 ms 1236 KB Output is correct
17 Correct 1 ms 1492 KB Output is correct
18 Correct 1 ms 1108 KB Output is correct
19 Correct 1 ms 1620 KB Output is correct
20 Correct 1 ms 1108 KB Output is correct
21 Correct 1 ms 1108 KB Output is correct
22 Correct 1 ms 980 KB Output is correct
23 Correct 2 ms 1108 KB Output is correct
24 Correct 1 ms 1236 KB Output is correct
25 Correct 2 ms 980 KB Output is correct
26 Correct 45 ms 22692 KB Output is correct
27 Correct 94 ms 23756 KB Output is correct
28 Correct 108 ms 23732 KB Output is correct
29 Correct 96 ms 22864 KB Output is correct
30 Correct 111 ms 22952 KB Output is correct
31 Correct 100 ms 23792 KB Output is correct
32 Correct 19 ms 17576 KB Output is correct
33 Correct 62 ms 23140 KB Output is correct
34 Correct 98 ms 23828 KB Output is correct
35 Correct 25 ms 23024 KB Output is correct
36 Correct 65 ms 22808 KB Output is correct
37 Correct 71 ms 22988 KB Output is correct
38 Correct 96 ms 22808 KB Output is correct
39 Correct 44 ms 23088 KB Output is correct
40 Correct 21 ms 21544 KB Output is correct
41 Incorrect 94 ms 2212 KB Output isn't correct
42 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 ms 1364 KB Output is correct
3 Correct 1 ms 1236 KB Output is correct
4 Correct 1 ms 1236 KB Output is correct
5 Correct 1 ms 1236 KB Output is correct
6 Correct 1 ms 1236 KB Output is correct
7 Correct 1 ms 1236 KB Output is correct
8 Correct 1 ms 1108 KB Output is correct
9 Correct 64 ms 288 KB Output is correct
10 Correct 18 ms 596 KB Output is correct
11 Correct 41 ms 1304 KB Output is correct
12 Correct 45 ms 1152 KB Output is correct
13 Correct 59 ms 1560 KB Output is correct
14 Correct 36 ms 1052 KB Output is correct
15 Correct 8 ms 468 KB Output is correct
16 Correct 36 ms 1052 KB Output is correct
17 Correct 92 ms 2324 KB Output is correct
18 Correct 56 ms 1424 KB Output is correct
19 Correct 2 ms 1364 KB Output is correct
20 Correct 1 ms 980 KB Output is correct
21 Correct 1 ms 1236 KB Output is correct
22 Correct 2 ms 1364 KB Output is correct
23 Correct 1 ms 1364 KB Output is correct
24 Correct 1 ms 1236 KB Output is correct
25 Correct 1 ms 1492 KB Output is correct
26 Correct 1 ms 1108 KB Output is correct
27 Correct 1 ms 1620 KB Output is correct
28 Correct 1 ms 1108 KB Output is correct
29 Correct 1 ms 1108 KB Output is correct
30 Correct 1 ms 980 KB Output is correct
31 Correct 2 ms 1108 KB Output is correct
32 Correct 1 ms 1236 KB Output is correct
33 Correct 2 ms 980 KB Output is correct
34 Correct 45 ms 22692 KB Output is correct
35 Correct 94 ms 23756 KB Output is correct
36 Correct 108 ms 23732 KB Output is correct
37 Correct 96 ms 22864 KB Output is correct
38 Correct 111 ms 22952 KB Output is correct
39 Correct 100 ms 23792 KB Output is correct
40 Correct 19 ms 17576 KB Output is correct
41 Correct 62 ms 23140 KB Output is correct
42 Correct 98 ms 23828 KB Output is correct
43 Correct 25 ms 23024 KB Output is correct
44 Correct 65 ms 22808 KB Output is correct
45 Correct 71 ms 22988 KB Output is correct
46 Correct 96 ms 22808 KB Output is correct
47 Correct 44 ms 23088 KB Output is correct
48 Correct 21 ms 21544 KB Output is correct
49 Incorrect 94 ms 2212 KB Output isn't correct
50 Halted 0 ms 0 KB -