답안 #768605

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
768605 2023-06-28T09:56:55 Z boris_mihov 미술 수업 (IOI13_artclass) C++17
0 / 100
158 ms 32020 KB
#include "artclass.h"
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <fstream>
#include <cassert>
#include <vector>
#include <set>

typedef long long llong;
const int MAXN = 500;
const int INF  = 1e9;

struct Cell
{
    int x, y, z;
    friend int operator - (const Cell &a, const Cell &b)
    {
        return abs(a.x - b.x) + abs(a.y - b.y) + abs(a.z - b.z);
    }

    friend bool operator < (const Cell &a, const Cell &b)
    {
        return (a.x < b.x || (a.x == b.x && a.y < b.y) || (a.x == b.x && a.y == b.y && a.z < b.z));
    }
};

const int CNTBASE = 7;
int compBase[CNTBASE] = {2, 5, 10, 15, 20, 50, 100};
bool close(Cell a, Cell b, int idx)
{
    return abs(a.x - b.x) < compBase[idx] && abs(a.y - b.y) < compBase[idx] && abs(a.z - b.z) < compBase[idx];
}

const int BASE = 5;
const int BASE2 = 10;
int convert(int x)
{
    if (x % BASE < BASE / 2) return x - (x % BASE);
    return x + BASE - (x % BASE);
}

std::set <Cell> s;
Cell pixel[MAXN][MAXN];
Cell block[MAXN][MAXN];
std::pair <int,int> delta[] = {{-1, 0}, {0, -1}, {1, 0}, {0, 1}};

bool out(int x, int y)
{
    return (x == -1 || y == -1 || x == MAXN / BASE2 || y == MAXN / BASE2);
}

bool outDFS(int x, int y)
{
    return (x == -1 || y == -1 || x == MAXN || y == MAXN);
}

bool vis[MAXN][MAXN][CNTBASE];
void dfs(int x, int y, int cnt)
{
    vis[x][y][cnt] = true;
    for (const auto &[dx, dy] : delta)
    {
        if (outDFS(x + dx, y + dy) || !close(pixel[x][y], pixel[x + dx][y + dy], cnt) || vis[x + dx][y + dy][cnt])
        {
            continue;
        }

        dfs(x + dx, y + dy, cnt);
    }
}

int style(int H, int W, int R[500][500], int G[500][500], int B[500][500]) 
{
    llong sum = 0;
    llong green = 0;
    for (int i = 0 ; i < MAXN ; ++i)
    {
        for (int j = 0 ; j < MAXN ; ++j)
        {
            sum += R[i][j];
            sum += G[i][j];
            sum += B[i][j];
            pixel[i][j] = {R[i][j], G[i][j], B[i][j]};
            block[i / BASE2][j / BASE2].x += R[i][j];
            block[i / BASE2][j / BASE2].y += G[i][j];
            block[i / BASE2][j / BASE2].z += B[i][j];
            green += (G[i][j] > 128);
            green -= (B[i][j] > 64 || G[i][j] > 64);
            s.insert({convert(R[i][j]), convert(G[i][j]), convert(B[i][j])});
        }
    }

    llong diff = 0;
    llong diff2 = 0;
    for (int i = 0 ; i * BASE2 < MAXN ; ++i)
    {
        for (int j = 0 ; j * BASE2 < MAXN ; ++j)
        {
            for (const auto &[dx, dy] : delta)
            {
                if (out(i + dx, j + dy))
                {
                    continue;
                }

                diff += block[i][j] - block[i + dx][j + dy];
            }   
        }
    }

    for (int i = 0 ; i < MAXN ; ++i)
    {
        for (int j = 0 ; j < MAXN ; ++j)
        {
            for (const auto &[dx, dy] : delta)
            {
                if (out(i + dx, j + dy))
                {
                    continue;
                }

                diff2 += pixel[i][j] - pixel[i + dx][j + dy];
            }   
        }
    }

    int compCnt[CNTBASE];
    for (int k = 0 ; k < CNTBASE ; ++k)
    {
        compCnt[k] = 0;
        for (int i = 0 ; i < MAXN ; ++i)
        {
            for (int j = 0 ; j < MAXN ; ++j)
            {
                if (!vis[i][j][k])
                {
                    compCnt[k]++;
                    dfs(i, j, k);
                }
            }
        }
    }

    std::ofstream file("results.txt", std::ios::app);
    for (int i = 0 ; i < CNTBASE ; ++i)
    {
        file << compCnt[i] << ' ';
    }

    file << '\n';
    file.close();

    for (int i = 0 ; i < CNTBASE ; ++i)
    {
        std::cout << compCnt[i] << ' ';
    }

    std::cout << '\n';

    if (0 <= compCnt[0] && compCnt[0] <= 1000000000  && 10201 <= compCnt[1] && compCnt[1] <= 1000000000  && 0 <= compCnt[2] && compCnt[2] <= 1000000000  && 0 <= compCnt[3] && compCnt[3] <= 1000000000  && 0 <= compCnt[4] && compCnt[4] <= 50  && 0 <= compCnt[5] && compCnt[5] <= 1000000000  && 0 <= compCnt[6] && compCnt[6] <= 1000000000 ) return 4;
    if (0 <= compCnt[0] && compCnt[0] <= 1000000000  && 9000 <= compCnt[1] && compCnt[1] <= 60000  && 0 <= compCnt[2] && compCnt[2] <= 1000000000  && 0 <= compCnt[3] && compCnt[3] <= 1000000000  && 0 <= compCnt[4] && compCnt[4] <= 18551  && 0 <= compCnt[5] && compCnt[5] <= 1000000000  && 0 <= compCnt[6] && compCnt[6] <= 1000000000 ) return 1;
    if (0 <= compCnt[0] && compCnt[0] <= 1000000000  && 0 <= compCnt[1] && compCnt[1] <= 60000  && 0 <= compCnt[2] && compCnt[2] <= 1000000000  && 99418 <= compCnt[3] && compCnt[3] <= 1000000000  && 150 <= compCnt[4] && compCnt[4] <= 1000000000  && 0 <= compCnt[5] && compCnt[5] <= 1000000000  && 0 <= compCnt[6] && compCnt[6] <= 1000000000 ) return 1;
    if (0 <= compCnt[0] && compCnt[0] <= 1000000000  && 0 <= compCnt[1] && compCnt[1] <= 9000  && 0 <= compCnt[2] && compCnt[2] <= 1000000000  && 0 <= compCnt[3] && compCnt[3] <= 1000000000  && 0 <= compCnt[4] && compCnt[4] <= 45183  && 0 <= compCnt[5] && compCnt[5] <= 1000000000  && 0 <= compCnt[6] && compCnt[6] <= 1000000000 ) return 4;
    if (0 <= compCnt[0] && compCnt[0] <= 1000000000  && 0 <= compCnt[1] && compCnt[1] <= 1000000000  && 0 <= compCnt[2] && compCnt[2] <= 1000000000  && 0 <= compCnt[3] && compCnt[3] <= 1000000000  && 0 <= compCnt[4] && compCnt[4] <= 150  && 0 <= compCnt[5] && compCnt[5] <= 1000000000  && 0 <= compCnt[6] && compCnt[6] <= 1000000000 ) return 4;
    if (0 <= compCnt[0] && compCnt[0] <= 1000000000  && 0 <= compCnt[1] && compCnt[1] <= 1000000000  && 0 <= compCnt[2] && compCnt[2] <= 1000000000  && 0 <= compCnt[3] && compCnt[3] <= 29581  && 0 <= compCnt[4] && compCnt[4] <= 15000  && 0 <= compCnt[5] && compCnt[5] <= 1000000000  && 0 <= compCnt[6] && compCnt[6] <= 1000000000 ) return 2;
    if (0 <= compCnt[0] && compCnt[0] <= 1000000000  && 132936 <= compCnt[1] && compCnt[1] <= 1000000000  && 0 <= compCnt[2] && compCnt[2] <= 1000000000  && 0 <= compCnt[3] && compCnt[3] <= 1000000000  && 0 <= compCnt[4] && compCnt[4] <= 42413  && 0 <= compCnt[5] && compCnt[5] <= 1000000000  && 0 <= compCnt[6] && compCnt[6] <= 1000000000 ) return -1;
    if (0 <= compCnt[0] && compCnt[0] <= 1000000000  && 0 <= compCnt[1] && compCnt[1] <= 1000000000  && 0 <= compCnt[2] && compCnt[2] <= 1000000000  && 0 <= compCnt[3] && compCnt[3] <= 1000000000  && 0 <= compCnt[4] && compCnt[4] <= 1000000000  && 0 <= compCnt[5] && compCnt[5] <= 1000000000  && 0 <= compCnt[6] && compCnt[6] <= 67 ) return -1;
    if (64406 <= compCnt[0] && compCnt[0] <= 1000000000  && 0 <= compCnt[1] && compCnt[1] <= 1000000000  && 0 <= compCnt[2] && compCnt[2] <= 1000000000  && 0 <= compCnt[3] && compCnt[3] <= 1000000000  && 0 <= compCnt[4] && compCnt[4] <= 1000000000  && 0 <= compCnt[5] && compCnt[5] <= 1000000000  && 0 <= compCnt[6] && compCnt[6] <= 1000000000 ) return -1;
    if (0 <= compCnt[0] && compCnt[0] <= 1000000000  && 0 <= compCnt[1] && compCnt[1] <= 1000000000  && 0 <= compCnt[2] && compCnt[2] <= 141047  && 0 <= compCnt[3] && compCnt[3] <= 1000000000  && 0 <= compCnt[4] && compCnt[4] <= 39267  && 0 <= compCnt[5] && compCnt[5] <= 1000000000  && 0 <= compCnt[6] && compCnt[6] <= 1000000000 ) return -1;
    if (0 <= compCnt[0] && compCnt[0] <= 1000000000  && 0 <= compCnt[1] && compCnt[1] <= 1000000000  && 0 <= compCnt[2] && compCnt[2] <= 22304  && 0 <= compCnt[3] && compCnt[3] <= 1000000000  && 0 <= compCnt[4] && compCnt[4] <= 1000000000  && 0 <= compCnt[5] && compCnt[5] <= 1000000000  && 0 <= compCnt[6] && compCnt[6] <= 1000000000 ) return -1;
    if (0 <= compCnt[0] && compCnt[0] <= 1000000000  && 0 <= compCnt[1] && compCnt[1] <= 1000000000  && 0 <= compCnt[2] && compCnt[2] <= 1000000000  && 82068 <= compCnt[3] && compCnt[3] <= 1000000000  && 0 <= compCnt[4] && compCnt[4] <= 1000000000  && 0 <= compCnt[5] && compCnt[5] <= 1000000000  && 0 <= compCnt[6] && compCnt[6] <= 1000000000 ) return -1;
    if (0 <= compCnt[0] && compCnt[0] <= 1000000000  && 0 <= compCnt[1] && compCnt[1] <= 1000000000  && 0 <= compCnt[2] && compCnt[2] <= 1000000000  && 0 <= compCnt[3] && compCnt[3] <= 1000000000  && 0 <= compCnt[4] && compCnt[4] <= 70025  && 4116 <= compCnt[5] && compCnt[5] <= 1000000000  && 0 <= compCnt[6] && compCnt[6] <= 1000000000 ) return -1;
    if (0 <= compCnt[0] && compCnt[0] <= 1000000000  && 0 <= compCnt[1] && compCnt[1] <= 1000000000  && 0 <= compCnt[2] && compCnt[2] <= 1000000000  && 0 <= compCnt[3] && compCnt[3] <= 1000000000  && 19065 <= compCnt[4] && compCnt[4] <= 1000000000  && 0 <= compCnt[5] && compCnt[5] <= 1000000000  && 0 <= compCnt[6] && compCnt[6] <= 1000000000 ) return -1;
    if (0 <= compCnt[0] && compCnt[0] <= 1000000000  && 0 <= compCnt[1] && compCnt[1] <= 1000000000  && 0 <= compCnt[2] && compCnt[2] <= 1000000000  && 0 <= compCnt[3] && compCnt[3] <= 1000000000  && 0 <= compCnt[4] && compCnt[4] <= 1000000000  && 0 <= compCnt[5] && compCnt[5] <= 1000000000  && 2 <= compCnt[6] && compCnt[6] <= 1000000000 ) return -1;
    if (0 <= compCnt[0] && compCnt[0] <= 1000000000  && 0 <= compCnt[1] && compCnt[1] <= 1000000000  && 0 <= compCnt[2] && compCnt[2] <= 76883  && 0 <= compCnt[3] && compCnt[3] <= 1000000000  && 0 <= compCnt[4] && compCnt[4] <= 1000000000  && 0 <= compCnt[5] && compCnt[5] <= 1119  && 0 <= compCnt[6] && compCnt[6] <= 1000000000 ) return -1;
    if (0 <= compCnt[0] && compCnt[0] <= 1000000000  && 0 <= compCnt[1] && compCnt[1] <= 1000000000  && 0 <= compCnt[2] && compCnt[2] <= 1000000000  && 0 <= compCnt[3] && compCnt[3] <= 1000000000  && 0 <= compCnt[4] && compCnt[4] <= 1000000000  && 4344 <= compCnt[5] && compCnt[5] <= 1000000000  && 0 <= compCnt[6] && compCnt[6] <= 1000000000 ) return -1;
    if (0 <= compCnt[0] && compCnt[0] <= 1000000000  && 0 <= compCnt[1] && compCnt[1] <= 1000000000  && 0 <= compCnt[2] && compCnt[2] <= 1000000000  && 0 <= compCnt[3] && compCnt[3] <= 1000000000  && 0 <= compCnt[4] && compCnt[4] <= 1000000000  && 0 <= compCnt[5] && compCnt[5] <= 4606  && 0 <= compCnt[6] && compCnt[6] <= 1000000000 ) return -1;
    if (0 <= compCnt[0] && compCnt[0] <= 214298  && 0 <= compCnt[1] && compCnt[1] <= 1000000000  && 0 <= compCnt[2] && compCnt[2] <= 1000000000  && 0 <= compCnt[3] && compCnt[3] <= 1000000000  && 0 <= compCnt[4] && compCnt[4] <= 1000000000  && 0 <= compCnt[5] && compCnt[5] <= 1000000000  && 0 <= compCnt[6] && compCnt[6] <= 1000000000 ) return -1;
    if (0 <= compCnt[0] && compCnt[0] <= 1000000000  && 0 <= compCnt[1] && compCnt[1] <= 36994  && 0 <= compCnt[2] && compCnt[2] <= 1000000000  && 0 <= compCnt[3] && compCnt[3] <= 1000000000  && 0 <= compCnt[4] && compCnt[4] <= 1000000000  && 0 <= compCnt[5] && compCnt[5] <= 1000000000  && 0 <= compCnt[6] && compCnt[6] <= 1000000000 ) return -1;
    return 3;
}
# 결과 실행 시간 메모리 Grader output
1 Incorrect 105 ms 27812 KB Output isn't correct
2 Incorrect 126 ms 27356 KB Output isn't correct
3 Incorrect 122 ms 29908 KB Output isn't correct
4 Incorrect 132 ms 31636 KB Output isn't correct
5 Incorrect 111 ms 24880 KB Output isn't correct
6 Incorrect 99 ms 21872 KB Output isn't correct
7 Incorrect 108 ms 20024 KB Output isn't correct
8 Incorrect 116 ms 24388 KB Output isn't correct
9 Incorrect 156 ms 24308 KB Output isn't correct
10 Incorrect 111 ms 22552 KB Output isn't correct
11 Incorrect 110 ms 27052 KB Output isn't correct
12 Incorrect 119 ms 31724 KB Output isn't correct
13 Incorrect 122 ms 23056 KB Output isn't correct
14 Incorrect 145 ms 31732 KB Output isn't correct
15 Incorrect 110 ms 31564 KB Output isn't correct
16 Incorrect 122 ms 29616 KB Output isn't correct
17 Incorrect 107 ms 31580 KB Output isn't correct
18 Incorrect 133 ms 27284 KB Output isn't correct
19 Incorrect 130 ms 31732 KB Output isn't correct
20 Incorrect 112 ms 24400 KB Output isn't correct
21 Incorrect 113 ms 26460 KB Output isn't correct
22 Incorrect 134 ms 26688 KB Output isn't correct
23 Incorrect 132 ms 28664 KB Output isn't correct
24 Incorrect 137 ms 25572 KB Output isn't correct
25 Incorrect 128 ms 30492 KB Output isn't correct
26 Incorrect 121 ms 23948 KB Output isn't correct
27 Incorrect 125 ms 29756 KB Output isn't correct
28 Incorrect 126 ms 28072 KB Output isn't correct
29 Incorrect 134 ms 31568 KB Output isn't correct
30 Incorrect 113 ms 27892 KB Output isn't correct
31 Incorrect 154 ms 29900 KB Output isn't correct
32 Incorrect 123 ms 28648 KB Output isn't correct
33 Incorrect 127 ms 31648 KB Output isn't correct
34 Incorrect 121 ms 25560 KB Output isn't correct
35 Incorrect 148 ms 27548 KB Output isn't correct
36 Incorrect 158 ms 28136 KB Output isn't correct
37 Incorrect 113 ms 31868 KB Output isn't correct
38 Incorrect 128 ms 29076 KB Output isn't correct
39 Incorrect 133 ms 26640 KB Output isn't correct
40 Incorrect 142 ms 27956 KB Output isn't correct
41 Incorrect 145 ms 27980 KB Output isn't correct
42 Incorrect 153 ms 30176 KB Output isn't correct
43 Incorrect 139 ms 27520 KB Output isn't correct
44 Incorrect 127 ms 28916 KB Output isn't correct
45 Incorrect 136 ms 28592 KB Output isn't correct
46 Incorrect 114 ms 25932 KB Output isn't correct
47 Incorrect 141 ms 25248 KB Output isn't correct
48 Incorrect 122 ms 31708 KB Output isn't correct
49 Incorrect 127 ms 29248 KB Output isn't correct
50 Incorrect 143 ms 27272 KB Output isn't correct
51 Incorrect 119 ms 28624 KB Output isn't correct
52 Incorrect 128 ms 30656 KB Output isn't correct
53 Incorrect 147 ms 26704 KB Output isn't correct
54 Incorrect 129 ms 27572 KB Output isn't correct
55 Incorrect 135 ms 30016 KB Output isn't correct
56 Incorrect 141 ms 31408 KB Output isn't correct
57 Incorrect 154 ms 27756 KB Output isn't correct
58 Incorrect 124 ms 23832 KB Output isn't correct
59 Incorrect 123 ms 24324 KB Output isn't correct
60 Incorrect 143 ms 31564 KB Output isn't correct
61 Incorrect 115 ms 27580 KB Output isn't correct
62 Incorrect 114 ms 25776 KB Output isn't correct
63 Incorrect 121 ms 31348 KB Output isn't correct
64 Incorrect 132 ms 30384 KB Output isn't correct
65 Incorrect 112 ms 21512 KB Output isn't correct
66 Incorrect 109 ms 21808 KB Output isn't correct
67 Incorrect 130 ms 29856 KB Output isn't correct
68 Incorrect 118 ms 21708 KB Output isn't correct
69 Incorrect 124 ms 29388 KB Output isn't correct
70 Incorrect 124 ms 27276 KB Output isn't correct
71 Incorrect 104 ms 20516 KB Output isn't correct
72 Incorrect 142 ms 30112 KB Output isn't correct
73 Incorrect 130 ms 31820 KB Output isn't correct
74 Incorrect 106 ms 25464 KB Output isn't correct
75 Incorrect 120 ms 31428 KB Output isn't correct
76 Incorrect 131 ms 27748 KB Output isn't correct
77 Incorrect 144 ms 31108 KB Output isn't correct
78 Incorrect 138 ms 28576 KB Output isn't correct
79 Incorrect 116 ms 27804 KB Output isn't correct
80 Incorrect 137 ms 23728 KB Output isn't correct
81 Incorrect 130 ms 29900 KB Output isn't correct
82 Incorrect 118 ms 21608 KB Output isn't correct
83 Incorrect 123 ms 28332 KB Output isn't correct
84 Incorrect 126 ms 31696 KB Output isn't correct
85 Incorrect 125 ms 32020 KB Output isn't correct
86 Incorrect 127 ms 30768 KB Output isn't correct
87 Incorrect 109 ms 31692 KB Output isn't correct
88 Incorrect 120 ms 24968 KB Output isn't correct
89 Incorrect 139 ms 30640 KB Output isn't correct
90 Incorrect 121 ms 26568 KB Output isn't correct
91 Incorrect 105 ms 19612 KB Output isn't correct
92 Incorrect 145 ms 29596 KB Output isn't correct
93 Incorrect 104 ms 29008 KB Output isn't correct
94 Incorrect 119 ms 26672 KB Output isn't correct
95 Incorrect 137 ms 30412 KB Output isn't correct
96 Incorrect 130 ms 27480 KB Output isn't correct
97 Incorrect 120 ms 26368 KB Output isn't correct
98 Incorrect 114 ms 26976 KB Output isn't correct
99 Incorrect 109 ms 22444 KB Output isn't correct
100 Incorrect 131 ms 29856 KB Output isn't correct
101 Incorrect 129 ms 29376 KB Output isn't correct
102 Incorrect 134 ms 28428 KB Output isn't correct