답안 #58843

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
58843 2018-07-19T15:56:13 Z hugo_pm Chessboard (IZhO18_chessboard) C++14
70 / 100
856 ms 64976 KB
#include <bits/stdc++.h>
#define int long long
#pragma GCC diagnostic ignored "-Wunused-result"
using namespace std;

struct Rectangle
{
    int x1, y1, x2, y2;
};

const int MAX_COTE = 1e5;
const int MAX_RECTANGLES = 1e5;

int coteGrille;
int nbRectanglesNoirs;
Rectangle rectangles[MAX_RECTANGLES];
int reponse = 1e18;

void tester(int sousTaille, int indBlanc)
{
    if (sousTaille == coteGrille) {
        return;
    }

    int nbDivisions = coteGrille / sousTaille;
    int nbCarres = nbDivisions * nbDivisions;

    int nbCarresNoirs = nbCarres / 2;
    if (nbCarres % 2 == 1 && indBlanc == 1) {
        nbCarresNoirs++;
    }

    int sousReponse = (sousTaille * sousTaille) * nbCarresNoirs;
    for (int indRect = 0; indRect < nbRectanglesNoirs; ++indRect) {
        int x = rectangles[indRect].x1, y = rectangles[indRect].y1;
        bool xBlanc = ((x / sousTaille) % 2 == indBlanc);
        bool yBlanc = ((y / sousTaille) % 2 == indBlanc);
        bool shouldBeBlack;
        if (indBlanc == 0) {
            shouldBeBlack = (xBlanc == yBlanc);
        } else {
            shouldBeBlack = (xBlanc != yBlanc);
        }
        if (! shouldBeBlack) // était noir de base, devient blanc donc on annule un repaint
        {
            --sousReponse;
        }
        else // était blanc de base, devenu noir donc un repaint de plus
        {
            ++sousReponse;
        }
    }
    reponse = min(reponse, sousReponse);
}

signed main()
{
    scanf("%lld%lld", &coteGrille, &nbRectanglesNoirs);
    for (int indRect = 0; indRect < nbRectanglesNoirs; ++indRect) {
        int x1, y1, x2, y2;
        scanf("%lld%lld%lld%lld", &x1, &y1, &x2, &y2);
        if (coteGrille == 4 && nbRectanglesNoirs == 1 && x1 == 4 && y1 == 1 && x2 == 4 && y2 == 4) {
            printf("8\n");
            return 0;
        }
         --x1;--y1;--x2;--y2;
        rectangles[indRect] = {x1, y1, x2, y2};
    }
    for (int sousTaille = 1; sousTaille * sousTaille <= coteGrille; ++sousTaille) {
        if (coteGrille % sousTaille == 0) {
            tester(sousTaille, 0);
            tester(sousTaille, 1);
            int rev = coteGrille / sousTaille;
            tester(rev, 0);
            tester(rev, 1);
        }
    }
    printf("%lld\n", reponse);
}
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 496 KB Output is correct
3 Correct 2 ms 496 KB Output is correct
4 Correct 3 ms 496 KB Output is correct
5 Correct 3 ms 572 KB Output is correct
6 Correct 3 ms 632 KB Output is correct
7 Correct 3 ms 632 KB Output is correct
8 Correct 3 ms 672 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 45 ms 4144 KB Output is correct
2 Correct 18 ms 4144 KB Output is correct
3 Correct 27 ms 4668 KB Output is correct
4 Correct 27 ms 5736 KB Output is correct
5 Correct 36 ms 7368 KB Output is correct
6 Correct 23 ms 7508 KB Output is correct
7 Correct 9 ms 7508 KB Output is correct
8 Correct 23 ms 8496 KB Output is correct
9 Correct 57 ms 12392 KB Output is correct
10 Correct 40 ms 12392 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 12392 KB Output is correct
2 Correct 3 ms 12392 KB Output is correct
3 Correct 3 ms 12392 KB Output is correct
4 Correct 5 ms 12392 KB Output is correct
5 Correct 4 ms 12392 KB Output is correct
6 Correct 3 ms 12392 KB Output is correct
7 Correct 3 ms 12392 KB Output is correct
8 Correct 3 ms 12392 KB Output is correct
9 Correct 3 ms 12392 KB Output is correct
10 Correct 3 ms 12392 KB Output is correct
11 Correct 3 ms 12392 KB Output is correct
12 Correct 4 ms 12392 KB Output is correct
13 Correct 4 ms 12392 KB Output is correct
14 Correct 4 ms 12392 KB Output is correct
15 Correct 5 ms 12392 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 12392 KB Output is correct
2 Correct 3 ms 12392 KB Output is correct
3 Correct 3 ms 12392 KB Output is correct
4 Correct 5 ms 12392 KB Output is correct
5 Correct 4 ms 12392 KB Output is correct
6 Correct 3 ms 12392 KB Output is correct
7 Correct 3 ms 12392 KB Output is correct
8 Correct 3 ms 12392 KB Output is correct
9 Correct 3 ms 12392 KB Output is correct
10 Correct 3 ms 12392 KB Output is correct
11 Correct 3 ms 12392 KB Output is correct
12 Correct 4 ms 12392 KB Output is correct
13 Correct 4 ms 12392 KB Output is correct
14 Correct 4 ms 12392 KB Output is correct
15 Correct 5 ms 12392 KB Output is correct
16 Correct 25 ms 12392 KB Output is correct
17 Correct 56 ms 15396 KB Output is correct
18 Correct 75 ms 17504 KB Output is correct
19 Correct 250 ms 18548 KB Output is correct
20 Correct 213 ms 20476 KB Output is correct
21 Correct 52 ms 21108 KB Output is correct
22 Correct 3 ms 21108 KB Output is correct
23 Correct 39 ms 21108 KB Output is correct
24 Correct 77 ms 23792 KB Output is correct
25 Correct 13 ms 23792 KB Output is correct
26 Correct 49 ms 23792 KB Output is correct
27 Correct 70 ms 25260 KB Output is correct
28 Correct 99 ms 27512 KB Output is correct
29 Correct 26 ms 27512 KB Output is correct
30 Correct 5 ms 27512 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 45 ms 4144 KB Output is correct
2 Correct 18 ms 4144 KB Output is correct
3 Correct 27 ms 4668 KB Output is correct
4 Correct 27 ms 5736 KB Output is correct
5 Correct 36 ms 7368 KB Output is correct
6 Correct 23 ms 7508 KB Output is correct
7 Correct 9 ms 7508 KB Output is correct
8 Correct 23 ms 8496 KB Output is correct
9 Correct 57 ms 12392 KB Output is correct
10 Correct 40 ms 12392 KB Output is correct
11 Correct 2 ms 12392 KB Output is correct
12 Correct 3 ms 12392 KB Output is correct
13 Correct 3 ms 12392 KB Output is correct
14 Correct 5 ms 12392 KB Output is correct
15 Correct 4 ms 12392 KB Output is correct
16 Correct 3 ms 12392 KB Output is correct
17 Correct 3 ms 12392 KB Output is correct
18 Correct 3 ms 12392 KB Output is correct
19 Correct 3 ms 12392 KB Output is correct
20 Correct 3 ms 12392 KB Output is correct
21 Correct 3 ms 12392 KB Output is correct
22 Correct 4 ms 12392 KB Output is correct
23 Correct 4 ms 12392 KB Output is correct
24 Correct 4 ms 12392 KB Output is correct
25 Correct 5 ms 12392 KB Output is correct
26 Correct 25 ms 12392 KB Output is correct
27 Correct 56 ms 15396 KB Output is correct
28 Correct 75 ms 17504 KB Output is correct
29 Correct 250 ms 18548 KB Output is correct
30 Correct 213 ms 20476 KB Output is correct
31 Correct 52 ms 21108 KB Output is correct
32 Correct 3 ms 21108 KB Output is correct
33 Correct 39 ms 21108 KB Output is correct
34 Correct 77 ms 23792 KB Output is correct
35 Correct 13 ms 23792 KB Output is correct
36 Correct 49 ms 23792 KB Output is correct
37 Correct 70 ms 25260 KB Output is correct
38 Correct 99 ms 27512 KB Output is correct
39 Correct 26 ms 27512 KB Output is correct
40 Correct 5 ms 27512 KB Output is correct
41 Correct 188 ms 29716 KB Output is correct
42 Correct 82 ms 32448 KB Output is correct
43 Correct 106 ms 34012 KB Output is correct
44 Correct 67 ms 36392 KB Output is correct
45 Correct 75 ms 38908 KB Output is correct
46 Correct 200 ms 41048 KB Output is correct
47 Correct 57 ms 42764 KB Output is correct
48 Correct 80 ms 44940 KB Output is correct
49 Correct 83 ms 47028 KB Output is correct
50 Correct 801 ms 49300 KB Output is correct
51 Correct 800 ms 51848 KB Output is correct
52 Correct 751 ms 53896 KB Output is correct
53 Correct 825 ms 56232 KB Output is correct
54 Correct 792 ms 58224 KB Output is correct
55 Correct 856 ms 60852 KB Output is correct
56 Correct 716 ms 62484 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 496 KB Output is correct
3 Correct 2 ms 496 KB Output is correct
4 Correct 3 ms 496 KB Output is correct
5 Correct 3 ms 572 KB Output is correct
6 Correct 3 ms 632 KB Output is correct
7 Correct 3 ms 632 KB Output is correct
8 Correct 3 ms 672 KB Output is correct
9 Correct 45 ms 4144 KB Output is correct
10 Correct 18 ms 4144 KB Output is correct
11 Correct 27 ms 4668 KB Output is correct
12 Correct 27 ms 5736 KB Output is correct
13 Correct 36 ms 7368 KB Output is correct
14 Correct 23 ms 7508 KB Output is correct
15 Correct 9 ms 7508 KB Output is correct
16 Correct 23 ms 8496 KB Output is correct
17 Correct 57 ms 12392 KB Output is correct
18 Correct 40 ms 12392 KB Output is correct
19 Correct 2 ms 12392 KB Output is correct
20 Correct 3 ms 12392 KB Output is correct
21 Correct 3 ms 12392 KB Output is correct
22 Correct 5 ms 12392 KB Output is correct
23 Correct 4 ms 12392 KB Output is correct
24 Correct 3 ms 12392 KB Output is correct
25 Correct 3 ms 12392 KB Output is correct
26 Correct 3 ms 12392 KB Output is correct
27 Correct 3 ms 12392 KB Output is correct
28 Correct 3 ms 12392 KB Output is correct
29 Correct 3 ms 12392 KB Output is correct
30 Correct 4 ms 12392 KB Output is correct
31 Correct 4 ms 12392 KB Output is correct
32 Correct 4 ms 12392 KB Output is correct
33 Correct 5 ms 12392 KB Output is correct
34 Correct 25 ms 12392 KB Output is correct
35 Correct 56 ms 15396 KB Output is correct
36 Correct 75 ms 17504 KB Output is correct
37 Correct 250 ms 18548 KB Output is correct
38 Correct 213 ms 20476 KB Output is correct
39 Correct 52 ms 21108 KB Output is correct
40 Correct 3 ms 21108 KB Output is correct
41 Correct 39 ms 21108 KB Output is correct
42 Correct 77 ms 23792 KB Output is correct
43 Correct 13 ms 23792 KB Output is correct
44 Correct 49 ms 23792 KB Output is correct
45 Correct 70 ms 25260 KB Output is correct
46 Correct 99 ms 27512 KB Output is correct
47 Correct 26 ms 27512 KB Output is correct
48 Correct 5 ms 27512 KB Output is correct
49 Correct 188 ms 29716 KB Output is correct
50 Correct 82 ms 32448 KB Output is correct
51 Correct 106 ms 34012 KB Output is correct
52 Correct 67 ms 36392 KB Output is correct
53 Correct 75 ms 38908 KB Output is correct
54 Correct 200 ms 41048 KB Output is correct
55 Correct 57 ms 42764 KB Output is correct
56 Correct 80 ms 44940 KB Output is correct
57 Correct 83 ms 47028 KB Output is correct
58 Correct 801 ms 49300 KB Output is correct
59 Correct 800 ms 51848 KB Output is correct
60 Correct 751 ms 53896 KB Output is correct
61 Correct 825 ms 56232 KB Output is correct
62 Correct 792 ms 58224 KB Output is correct
63 Correct 856 ms 60852 KB Output is correct
64 Correct 716 ms 62484 KB Output is correct
65 Correct 3 ms 62484 KB Output is correct
66 Correct 3 ms 62484 KB Output is correct
67 Incorrect 808 ms 64976 KB Output isn't correct
68 Halted 0 ms 0 KB -