답안 #768539

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
768539 2023-06-28T08:53:52 Z boris_mihov 미술 수업 (IOI13_artclass) C++17
60 / 100
95 ms 22400 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 BASE3 = 5;
const int BASE4 = 20;
bool close(Cell a, Cell b)
{
    return abs(a.x - b.x) < BASE3 && abs(a.y - b.y) < BASE3 && abs(a.z - b.z) < BASE3;
}

bool close2(Cell a, Cell b)
{
    return abs(a.x - b.x) < BASE4 && abs(a.y - b.y) < BASE4 && abs(a.z - b.z) < BASE4;
}

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];
bool vis2[MAXN][MAXN];
void dfs(int x, int y)
{
    vis[x][y] = true;
    for (const auto &[dx, dy] : delta)
    {
        if (outDFS(x + dx, y + dy) || !close(pixel[x][y], pixel[x + dx][y + dy]) || vis[x + dx][y + dy])
        {
            continue;
        }

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

void dfs2(int x, int y)
{
    vis2[x][y] = true;
    for (const auto &[dx, dy] : delta)
    {
        if (outDFS(x + dx, y + dy) || !close2(pixel[x][y], pixel[x + dx][y + dy]) || vis2[x + dx][y + dy])
        {
            continue;
        }

        dfs2(x + dx, y + dy);
    }
}

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 = 0;
    for (int i = 0 ; i < MAXN ; ++i)
    {
        for (int j = 0 ; j < MAXN ; ++j)
        {
            if (!vis[i][j])
            {
                compCnt++;
                dfs(i, j);
            }
        }
    }

    int compCnt2 = 0;
    for (int i = 0 ; i < MAXN ; ++i)
    {
        for (int j = 0 ; j < MAXN ; ++j)
        {
            if (!vis2[i][j])
            {
                compCnt2++;
                dfs2(i, j);
            }
        }
    }

    srand(time(nullptr));
    double ratio = (double)green / (MAXN * MAXN);
    double ratio2 = (double)s.size() / (MAXN * MAXN);
    if (compCnt < 9000) return 4;
    if (compCnt < 60000) return 1;
    if (compCnt2 < 15000) return 2;
    // if (ratio > 0.3) return 2;
    // return 3;
    return 3;
}

Compilation message

artclass.cpp: In function 'int style(int, int, int (*)[500], int (*)[500], int (*)[500])':
artclass.cpp:175:12: warning: unused variable 'ratio' [-Wunused-variable]
  175 |     double ratio = (double)green / (MAXN * MAXN);
      |            ^~~~~
artclass.cpp:176:12: warning: unused variable 'ratio2' [-Wunused-variable]
  176 |     double ratio2 = (double)s.size() / (MAXN * MAXN);
      |            ^~~~~~
# 결과 실행 시간 메모리 Grader output
1 Incorrect 71 ms 9960 KB Output isn't correct
2 Correct 60 ms 15616 KB Output is correct
3 Correct 68 ms 22400 KB Output is correct
4 Correct 70 ms 11696 KB Output is correct
5 Correct 64 ms 18028 KB Output is correct
6 Incorrect 71 ms 13272 KB Output isn't correct
7 Correct 70 ms 15400 KB Output is correct
8 Correct 95 ms 10188 KB Output is correct
9 Incorrect 72 ms 16044 KB Output isn't correct
10 Correct 83 ms 12368 KB Output is correct
11 Correct 59 ms 15060 KB Output is correct
12 Incorrect 67 ms 16348 KB Output isn't correct
13 Incorrect 85 ms 16060 KB Output isn't correct
14 Incorrect 89 ms 7428 KB Output isn't correct
15 Correct 84 ms 9476 KB Output is correct
16 Correct 75 ms 14048 KB Output is correct
17 Correct 84 ms 15132 KB Output is correct
18 Correct 76 ms 12236 KB Output is correct
19 Correct 70 ms 14508 KB Output is correct
20 Incorrect 85 ms 12956 KB Output isn't correct
21 Correct 55 ms 13528 KB Output is correct
22 Incorrect 78 ms 8944 KB Output isn't correct
23 Correct 65 ms 14764 KB Output is correct
24 Correct 92 ms 10988 KB Output is correct
25 Correct 76 ms 10284 KB Output is correct
26 Incorrect 90 ms 7860 KB Output isn't correct
27 Correct 82 ms 10220 KB Output is correct
28 Correct 95 ms 12428 KB Output is correct
29 Correct 61 ms 10112 KB Output is correct
30 Correct 53 ms 13552 KB Output is correct
31 Incorrect 51 ms 13620 KB Output isn't correct
32 Correct 66 ms 14204 KB Output is correct
33 Incorrect 54 ms 13480 KB Output isn't correct
34 Incorrect 86 ms 10164 KB Output isn't correct
35 Correct 75 ms 11012 KB Output is correct
36 Correct 58 ms 11724 KB Output is correct
37 Correct 67 ms 9732 KB Output is correct
38 Incorrect 70 ms 10584 KB Output isn't correct
39 Correct 73 ms 13004 KB Output is correct
40 Correct 80 ms 10168 KB Output is correct
41 Correct 52 ms 14924 KB Output is correct
42 Correct 52 ms 13736 KB Output is correct
43 Incorrect 53 ms 12912 KB Output isn't correct
44 Correct 72 ms 14200 KB Output is correct
45 Correct 71 ms 10124 KB Output is correct
46 Correct 59 ms 11732 KB Output is correct
47 Correct 67 ms 12704 KB Output is correct
48 Correct 52 ms 13216 KB Output is correct
49 Correct 74 ms 10460 KB Output is correct
50 Incorrect 37 ms 17228 KB Output isn't correct
51 Correct 63 ms 16988 KB Output is correct
52 Correct 62 ms 12344 KB Output is correct
53 Incorrect 79 ms 15784 KB Output isn't correct
54 Correct 66 ms 11072 KB Output is correct
55 Correct 85 ms 11980 KB Output is correct
56 Correct 74 ms 12212 KB Output is correct
57 Correct 53 ms 13360 KB Output is correct
58 Correct 60 ms 18892 KB Output is correct
59 Correct 59 ms 14040 KB Output is correct
60 Correct 52 ms 14928 KB Output is correct
61 Correct 71 ms 15988 KB Output is correct
62 Correct 70 ms 10080 KB Output is correct
63 Correct 62 ms 9932 KB Output is correct
64 Correct 52 ms 13656 KB Output is correct
65 Incorrect 61 ms 12500 KB Output isn't correct
66 Correct 68 ms 11596 KB Output is correct
67 Correct 60 ms 19788 KB Output is correct
68 Incorrect 72 ms 13132 KB Output isn't correct
69 Correct 57 ms 16460 KB Output is correct
70 Correct 64 ms 8388 KB Output is correct
71 Correct 82 ms 10872 KB Output is correct
72 Incorrect 77 ms 9372 KB Output isn't correct
73 Incorrect 65 ms 10468 KB Output isn't correct
74 Correct 68 ms 15464 KB Output is correct
75 Correct 57 ms 12020 KB Output is correct
76 Incorrect 62 ms 14720 KB Output isn't correct
77 Correct 54 ms 13448 KB Output is correct
78 Incorrect 73 ms 9720 KB Output isn't correct
79 Incorrect 73 ms 13212 KB Output isn't correct
80 Incorrect 60 ms 11668 KB Output isn't correct
81 Correct 60 ms 18404 KB Output is correct
82 Correct 59 ms 14268 KB Output is correct
83 Correct 72 ms 11108 KB Output is correct
84 Incorrect 68 ms 10188 KB Output isn't correct
85 Correct 68 ms 10568 KB Output is correct
86 Correct 73 ms 12492 KB Output is correct
87 Correct 79 ms 11468 KB Output is correct
88 Correct 54 ms 16648 KB Output is correct
89 Incorrect 75 ms 13272 KB Output isn't correct
90 Correct 72 ms 11188 KB Output is correct
91 Correct 65 ms 13808 KB Output is correct
92 Correct 57 ms 10572 KB Output is correct
93 Correct 85 ms 11916 KB Output is correct
94 Incorrect 74 ms 10588 KB Output isn't correct
95 Correct 62 ms 13576 KB Output is correct
96 Correct 71 ms 20168 KB Output is correct
97 Incorrect 57 ms 15844 KB Output isn't correct
98 Correct 74 ms 10488 KB Output is correct
99 Correct 62 ms 10152 KB Output is correct
100 Correct 71 ms 10888 KB Output is correct
101 Correct 69 ms 10828 KB Output is correct
102 Correct 35 ms 18864 KB Output is correct