답안 #768659

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
768659 2023-06-28T10:41:02 Z boris_mihov 미술 수업 (IOI13_artclass) C++17
60 / 100
143 ms 32072 KB
#include "artclass.h"
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <numeric>
#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);
                }
            }
        }
    }

    if (compCnt[6] > 10) return 3;
    if (compCnt[6] <= 3 && compCnt[4] < 50) return 4;
    if (compCnt[1] < 60000 && (compCnt[1] > 9000 || compCnt[4] > 150)) return 1;
    if (compCnt[6] <= 3 && (compCnt[1] < 9000 || compCnt[4] < 150)) return 4;
    if (compCnt[6] <= 5 && compCnt[4] < 15000) return 2;
    return 3;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 101 ms 20556 KB Output is correct
2 Correct 129 ms 28416 KB Output is correct
3 Correct 128 ms 27576 KB Output is correct
4 Correct 124 ms 28376 KB Output is correct
5 Correct 122 ms 30084 KB Output is correct
6 Incorrect 114 ms 27548 KB Output isn't correct
7 Correct 109 ms 31512 KB Output is correct
8 Incorrect 137 ms 30148 KB Output isn't correct
9 Correct 112 ms 25500 KB Output is correct
10 Correct 104 ms 25420 KB Output is correct
11 Correct 120 ms 26524 KB Output is correct
12 Correct 115 ms 29712 KB Output is correct
13 Correct 116 ms 27840 KB Output is correct
14 Correct 107 ms 31736 KB Output is correct
15 Incorrect 127 ms 27476 KB Output isn't correct
16 Incorrect 112 ms 31748 KB Output isn't correct
17 Incorrect 131 ms 27744 KB Output isn't correct
18 Correct 120 ms 29112 KB Output is correct
19 Correct 140 ms 31456 KB Output is correct
20 Correct 111 ms 31644 KB Output is correct
21 Correct 123 ms 26612 KB Output is correct
22 Correct 111 ms 24780 KB Output is correct
23 Correct 143 ms 30116 KB Output is correct
24 Correct 109 ms 28476 KB Output is correct
25 Correct 116 ms 25820 KB Output is correct
26 Correct 136 ms 31708 KB Output is correct
27 Incorrect 133 ms 24360 KB Output isn't correct
28 Incorrect 131 ms 28204 KB Output isn't correct
29 Correct 125 ms 27244 KB Output is correct
30 Correct 127 ms 30724 KB Output is correct
31 Correct 118 ms 31708 KB Output is correct
32 Correct 122 ms 29380 KB Output is correct
33 Correct 121 ms 26588 KB Output is correct
34 Correct 127 ms 29880 KB Output is correct
35 Incorrect 132 ms 23608 KB Output isn't correct
36 Incorrect 124 ms 27820 KB Output isn't correct
37 Incorrect 125 ms 28496 KB Output isn't correct
38 Correct 124 ms 27268 KB Output is correct
39 Correct 123 ms 32072 KB Output is correct
40 Correct 139 ms 27836 KB Output is correct
41 Correct 101 ms 22392 KB Output is correct
42 Correct 138 ms 27468 KB Output is correct
43 Incorrect 118 ms 29004 KB Output isn't correct
44 Correct 139 ms 29812 KB Output is correct
45 Incorrect 110 ms 21508 KB Output isn't correct
46 Correct 117 ms 25248 KB Output is correct
47 Correct 107 ms 27820 KB Output is correct
48 Correct 125 ms 25456 KB Output is correct
49 Correct 122 ms 23896 KB Output is correct
50 Correct 117 ms 28720 KB Output is correct
51 Correct 118 ms 31424 KB Output is correct
52 Correct 133 ms 30292 KB Output is correct
53 Correct 130 ms 31692 KB Output is correct
54 Correct 115 ms 26752 KB Output is correct
55 Correct 126 ms 30604 KB Output is correct
56 Correct 110 ms 24408 KB Output is correct
57 Correct 119 ms 24408 KB Output is correct
58 Incorrect 110 ms 26908 KB Output isn't correct
59 Correct 122 ms 29656 KB Output is correct
60 Correct 134 ms 31636 KB Output is correct
61 Correct 110 ms 27264 KB Output is correct
62 Incorrect 130 ms 31032 KB Output isn't correct
63 Correct 114 ms 21944 KB Output is correct
64 Incorrect 116 ms 24920 KB Output isn't correct
65 Correct 127 ms 29760 KB Output is correct
66 Incorrect 128 ms 31808 KB Output isn't correct
67 Incorrect 124 ms 27352 KB Output isn't correct
68 Correct 140 ms 31616 KB Output is correct
69 Incorrect 133 ms 28552 KB Output isn't correct
70 Correct 132 ms 30620 KB Output is correct
71 Correct 121 ms 25616 KB Output is correct
72 Correct 120 ms 31624 KB Output is correct
73 Correct 128 ms 29500 KB Output is correct
74 Correct 115 ms 29860 KB Output is correct
75 Correct 113 ms 22500 KB Output is correct
76 Correct 139 ms 30480 KB Output is correct
77 Correct 113 ms 23768 KB Output is correct
78 Correct 133 ms 26676 KB Output is correct
79 Incorrect 125 ms 29168 KB Output isn't correct
80 Correct 138 ms 21792 KB Output is correct
81 Incorrect 115 ms 21784 KB Output isn't correct
82 Incorrect 118 ms 27956 KB Output isn't correct
83 Correct 136 ms 30432 KB Output is correct
84 Correct 127 ms 31280 KB Output is correct
85 Incorrect 128 ms 27496 KB Output isn't correct
86 Correct 119 ms 26332 KB Output is correct
87 Incorrect 116 ms 24268 KB Output isn't correct
88 Correct 138 ms 26384 KB Output is correct
89 Incorrect 121 ms 29388 KB Output isn't correct
90 Incorrect 113 ms 19948 KB Output isn't correct
91 Correct 134 ms 31628 KB Output is correct
92 Correct 112 ms 21472 KB Output is correct
93 Correct 126 ms 27936 KB Output is correct
94 Incorrect 132 ms 28180 KB Output isn't correct
95 Incorrect 125 ms 23016 KB Output isn't correct
96 Correct 98 ms 19616 KB Output is correct
97 Correct 128 ms 31692 KB Output is correct
98 Correct 124 ms 28572 KB Output is correct
99 Incorrect 117 ms 27048 KB Output isn't correct
100 Correct 122 ms 31764 KB Output is correct
101 Correct 104 ms 28972 KB Output is correct
102 Correct 123 ms 29900 KB Output is correct