Submission #747057

# Submission time Handle Problem Language Result Execution time Memory
747057 2023-05-23T14:19:32 Z heeheeheehaaw Chessboard (IZhO18_chessboard) C++17
39 / 100
113 ms 12016 KB
#include <iostream>
#include <vector>

using namespace std;

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

int 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 980 KB Output is correct
3 Correct 1 ms 980 KB Output is correct
4 Correct 1 ms 980 KB Output is correct
5 Correct 1 ms 980 KB Output is correct
6 Correct 1 ms 980 KB Output is correct
7 Correct 1 ms 980 KB Output is correct
8 Correct 1 ms 980 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 63 ms 212 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 1108 KB Output is correct
2 Correct 1 ms 852 KB Output is correct
3 Correct 1 ms 1212 KB Output is correct
4 Correct 2 ms 1236 KB Output is correct
5 Correct 1 ms 1108 KB Output is correct
6 Correct 1 ms 1108 KB Output is correct
7 Correct 2 ms 1236 KB Output is correct
8 Correct 1 ms 980 KB Output is correct
9 Correct 2 ms 1364 KB Output is correct
10 Correct 1 ms 980 KB Output is correct
11 Correct 1 ms 980 KB Output is correct
12 Correct 1 ms 852 KB Output is correct
13 Correct 1 ms 980 KB Output is correct
14 Correct 2 ms 1108 KB Output is correct
15 Correct 2 ms 852 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 1108 KB Output is correct
2 Correct 1 ms 852 KB Output is correct
3 Correct 1 ms 1212 KB Output is correct
4 Correct 2 ms 1236 KB Output is correct
5 Correct 1 ms 1108 KB Output is correct
6 Correct 1 ms 1108 KB Output is correct
7 Correct 2 ms 1236 KB Output is correct
8 Correct 1 ms 980 KB Output is correct
9 Correct 2 ms 1364 KB Output is correct
10 Correct 1 ms 980 KB Output is correct
11 Correct 1 ms 980 KB Output is correct
12 Correct 1 ms 852 KB Output is correct
13 Correct 1 ms 980 KB Output is correct
14 Correct 2 ms 1108 KB Output is correct
15 Correct 2 ms 852 KB Output is correct
16 Correct 42 ms 11516 KB Output is correct
17 Correct 79 ms 12016 KB Output is correct
18 Correct 91 ms 11980 KB Output is correct
19 Correct 92 ms 11500 KB Output is correct
20 Correct 113 ms 11500 KB Output is correct
21 Correct 76 ms 12016 KB Output is correct
22 Correct 13 ms 9556 KB Output is correct
23 Correct 46 ms 11660 KB Output is correct
24 Correct 87 ms 12016 KB Output is correct
25 Correct 18 ms 11744 KB Output is correct
26 Correct 61 ms 11468 KB Output is correct
27 Correct 66 ms 11640 KB Output is correct
28 Correct 94 ms 11488 KB Output is correct
29 Correct 37 ms 11664 KB Output is correct
30 Correct 17 ms 11604 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 63 ms 212 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 ms 980 KB Output is correct
3 Correct 1 ms 980 KB Output is correct
4 Correct 1 ms 980 KB Output is correct
5 Correct 1 ms 980 KB Output is correct
6 Correct 1 ms 980 KB Output is correct
7 Correct 1 ms 980 KB Output is correct
8 Correct 1 ms 980 KB Output is correct
9 Incorrect 63 ms 212 KB Output isn't correct
10 Halted 0 ms 0 KB -