Submission #747056

# Submission time Handle Problem Language Result Execution time Memory
747056 2023-05-23T14:15:10 Z heeheeheehaaw Chessboard (IZhO18_chessboard) C++17
39 / 100
205 ms 12056 KB
#include <iostream>
#include <vector>

using namespace std;

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

int main()
{
    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;
    }

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

            minn = min(minn, sum);
        }

        cout<<minn<<'\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 2 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 Runtime error 205 ms 1756 KB Execution killed with signal 11
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 1108 KB Output is correct
4 Correct 1 ms 1236 KB Output is correct
5 Correct 2 ms 1120 KB Output is correct
6 Correct 2 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 1 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 2 ms 1084 KB Output is correct
14 Correct 2 ms 1108 KB Output is correct
15 Correct 1 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 1108 KB Output is correct
4 Correct 1 ms 1236 KB Output is correct
5 Correct 2 ms 1120 KB Output is correct
6 Correct 2 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 1 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 2 ms 1084 KB Output is correct
14 Correct 2 ms 1108 KB Output is correct
15 Correct 1 ms 852 KB Output is correct
16 Correct 36 ms 11400 KB Output is correct
17 Correct 79 ms 12056 KB Output is correct
18 Correct 102 ms 11980 KB Output is correct
19 Correct 92 ms 11596 KB Output is correct
20 Correct 97 ms 11628 KB Output is correct
21 Correct 83 ms 12016 KB Output is correct
22 Correct 15 ms 9592 KB Output is correct
23 Correct 48 ms 11736 KB Output is correct
24 Correct 94 ms 12020 KB Output is correct
25 Correct 21 ms 11732 KB Output is correct
26 Correct 57 ms 11464 KB Output is correct
27 Correct 66 ms 11656 KB Output is correct
28 Correct 91 ms 11480 KB Output is correct
29 Correct 52 ms 11724 KB Output is correct
30 Correct 15 ms 11564 KB Output is correct
# Verdict Execution time Memory Grader output
1 Runtime error 205 ms 1756 KB Execution killed with signal 11
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 2 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 Runtime error 205 ms 1756 KB Execution killed with signal 11
10 Halted 0 ms 0 KB -