답안 #779426

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
779426 2023-07-11T11:49:11 Z vjudge1 Chessboard (IZhO18_chessboard) C++17
39 / 100
126 ms 4596 KB
#include <iostream>
#define MAX 1000
using namespace std;
///ifstream cin ("c.in");
///ofstream cout ("c.out");
int a[MAX + 10][MAX + 10];
void speedy()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
}
int prime(int x)
{
    for (int d = 2; d * d <= x; d++)
        if (x % d == 0)
            return 0;
    return 1;
}
int main()
{
    speedy();
    int n, k;
    cin >> n >> k;
    if (prime(n) == 1)
    {
        long long change1 = n * n / 2, change2 = n * n / 2 + 1;
        for (int kk = 1; kk <= k; kk++)
        {
            int x1, y1, x2, y2;
            cin >> x1 >> y1 >> x2 >> y2;
            ///make (1, 1) white
            if (x1 % 2 == 1 && y1 % 2 == 1)
            {
                change1++;
                change2--;
            }
            if (x1 % 2 == 0 && y1 % 2 == 0)
            {
                change1++;
                change2--;
            }
            ///make (1, 1) black
            if (x1 % 2 == 1 && y1 % 2 == 0)
            {
                change2++;
                change1--;
            }
            if (x1 % 2 == 0 && y1 % 2 == 1)
            {
                change2++;
                change1--;
            }
        }
        cout << min(change1, change2);
    }
    else
    {
        for (int kk = 1; kk <= k; kk++)
        {
            int x1, y1, x2, y2;
            cin >> x1 >> y1 >> x2 >> y2;
            for (int i = x1; i <= x2; i++)
                for (int j = y1; j <= y2; j++)
                    a[i][j] = 1;
        }
        int ans = n * n + 10;
        for (int side = 1; side < n; side++)
            if (n % side == 0)
            {
                int change, cnt = n / side;
                ///make (1, 1, side, side) white
                change = 0;
                for (int auxi = 1; auxi <= cnt; auxi++)
                    for (int auxj = 1; auxj <= cnt; auxj++)
                        for (int i = side * (auxi - 1) + 1; i <= side * auxi; i++)
                            for (int j = side * (auxj - 1) + 1; j <= side * auxj; j++)
                            {
                                if (auxi % 2 == 1 && auxj % 2 == 1)
                                    if (a[i][j] == 1)
                                        change++;
                                if (auxi % 2 == 1 && auxj % 2 == 0)
                                    if (a[i][j] == 0)
                                        change++;
                                if (auxi % 2 == 0 && auxj % 2 == 1)
                                    if (a[i][j] == 0)
                                        change++;
                                if (auxi % 2 == 0 && auxj % 2 == 0)
                                    if (a[i][j] == 1)
                                        change++;
                            }
                ans = min(ans, change);
                ///make (1, 1, side, side) black
                change = 0;
                for (int auxi = 1; auxi <= cnt; auxi++)
                    for (int auxj = 1; auxj <= cnt; auxj++)
                        for (int i = side * (auxi - 1) + 1; i <= side * auxi; i++)
                            for (int j = side * (auxj - 1) + 1; j <= side * auxj; j++)
                            {
                                if (auxi % 2 == 1 && auxj % 2 == 1)
                                    if (a[i][j] == 0)
                                        change++;
                                if (auxi % 2 == 1 && auxj % 2 == 0)
                                    if (a[i][j] == 1)
                                        change++;
                                if (auxi % 2 == 0 && auxj % 2 == 1)
                                    if (a[i][j] == 1)
                                        change++;
                                if (auxi % 2 == 0 && auxj % 2 == 0)
                                    if (a[i][j] == 0)
                                        change++;
                            }
                ans = min(ans, change);
            }
        cout << ans;
    }
    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 212 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 212 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Incorrect 16 ms 1716 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 596 KB Output is correct
2 Correct 1 ms 452 KB Output is correct
3 Correct 1 ms 596 KB Output is correct
4 Correct 1 ms 596 KB Output is correct
5 Correct 1 ms 596 KB Output is correct
6 Correct 1 ms 596 KB Output is correct
7 Correct 1 ms 596 KB Output is correct
8 Correct 1 ms 468 KB Output is correct
9 Correct 1 ms 596 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 1 ms 596 KB Output is correct
12 Correct 1 ms 212 KB Output is correct
13 Correct 1 ms 596 KB Output is correct
14 Correct 1 ms 596 KB Output is correct
15 Correct 1 ms 468 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 596 KB Output is correct
2 Correct 1 ms 452 KB Output is correct
3 Correct 1 ms 596 KB Output is correct
4 Correct 1 ms 596 KB Output is correct
5 Correct 1 ms 596 KB Output is correct
6 Correct 1 ms 596 KB Output is correct
7 Correct 1 ms 596 KB Output is correct
8 Correct 1 ms 468 KB Output is correct
9 Correct 1 ms 596 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 1 ms 596 KB Output is correct
12 Correct 1 ms 212 KB Output is correct
13 Correct 1 ms 596 KB Output is correct
14 Correct 1 ms 596 KB Output is correct
15 Correct 1 ms 468 KB Output is correct
16 Correct 18 ms 4436 KB Output is correct
17 Correct 19 ms 592 KB Output is correct
18 Correct 40 ms 4556 KB Output is correct
19 Correct 120 ms 4488 KB Output is correct
20 Correct 126 ms 4484 KB Output is correct
21 Correct 22 ms 696 KB Output is correct
22 Correct 43 ms 1780 KB Output is correct
23 Correct 33 ms 4528 KB Output is correct
24 Correct 38 ms 4596 KB Output is correct
25 Correct 28 ms 4292 KB Output is correct
26 Correct 28 ms 4468 KB Output is correct
27 Correct 41 ms 4508 KB Output is correct
28 Correct 35 ms 4392 KB Output is correct
29 Correct 7 ms 596 KB Output is correct
30 Correct 12 ms 3996 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Incorrect 16 ms 1716 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 212 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 212 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Incorrect 16 ms 1716 KB Output isn't correct
10 Halted 0 ms 0 KB -