답안 #920202

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
920202 2024-02-02T09:07:26 Z danikoynov 무지개나라 (APIO17_rainbow) C++14
35 / 100
3000 ms 28900 KB
#include "rainbow.h"
#include<bits/stdc++.h>

using namespace std;

const int inf = 1e9;

set < pair < int, int > > nodes, ver_edges, hor_edges, river;
int min_x = inf, max_x = -inf, min_y = inf, max_y = -inf;

void add_node(int x, int y)
{
    nodes.insert({x, y});
}

void add_hor_edge(int x, int y)
{
    hor_edges.insert({x, y});
}

void add_ver_edge(int x, int y)
{
    ver_edges.insert({x, y});
}

void add_river(int x, int y)
{
    add_node(x, y);
    add_node(x, y + 1);
    add_node(x + 1, y);
    add_node(x + 1, y + 1);
    add_hor_edge(x, y);
    add_hor_edge(x + 1, y);
    add_ver_edge(x, y);
    add_ver_edge(x, y + 1);
    min_x = min(min_x, x);
    max_x = max(max_x, x);
    min_y = min(min_y, y);
    max_y = max(max_y, y);
    river.insert({x, y});
}

void init(int R, int C, int sr, int sc, int M, char *S)
{
    add_river(sr, sc);
    for (int i = 0; i < M; i ++)
    {
        if (S[i] == 'N')
            sr --;
        else
        if (S[i] == 'S')
            sr ++;
        else
        if (S[i] == 'W')
            sc --;
        else
        if (S[i] == 'E')
            sc ++;
        else assert(false);

        add_river(sr, sc);
    }
}

int query_nodes(int ar, int ac, int br, int bc)
{
    int cnt = 0;
    for (pair < int, int > cur : nodes)
    {
        if (cur.first >= ar && cur.first <= br &&
            cur.second >= ac && cur.second <= bc)
                cnt ++;
    }
    return cnt;
}

int query_hor_edges(int ar, int ac, int br, int bc)
{
    int cnt = 0;
    for (pair < int, int > cur : hor_edges)
    {
        if (cur.first >= ar && cur.first <= br &&
            cur.second >= ac && cur.second <= bc)
                cnt ++;
    }
    return cnt;
}

int query_ver_edges(int ar, int ac, int br, int bc)
{
    int cnt = 0;
    for (pair < int, int > cur : ver_edges)
    {
        if (cur.first >= ar && cur.first <= br &&
            cur.second >= ac && cur.second <= bc)
                cnt ++;
    }
    return cnt;
}

int query_river(int ar, int ac, int br, int bc)
{
    int cnt = 0;
    for (pair < int, int > cur : river)
    {
        if (cur.first >= ar && cur.first <= br &&
            cur.second >= ac && cur.second <= bc)
                cnt ++;
    }
    return cnt;
}

int colour(int ar, int ac, int br, int bc)
{
    int V = query_nodes(ar + 1, ac + 1, br, bc) + (br - ar + 2) * 2 + (bc - ac) * 2;
    int E = 0;
    E = E + query_hor_edges(ar + 1, ac, br, bc) + (bc - ac + 1) * 2;
    E = E + query_ver_edges(ar, ac + 1, br, bc) + (br - ar + 1) * 2;
    int C = 1;
    if (ar < min_x && ac < min_y && br > max_x && bc > max_y)
        C ++;
    /// V + F = E + C + 1
    /// F = E - V + C + 1
    int F = E - V + C - query_river(ar, ac, br, bc);
    ///cout << "V " << V << " E " << E << " C " << C << endl;
    return F;
}

# 결과 실행 시간 메모리 Grader output
1 Correct 6 ms 344 KB Output is correct
2 Correct 30 ms 600 KB Output is correct
3 Correct 8 ms 600 KB Output is correct
4 Correct 8 ms 348 KB Output is correct
5 Correct 37 ms 600 KB Output is correct
6 Correct 0 ms 344 KB Output is correct
7 Correct 0 ms 344 KB Output is correct
8 Correct 1 ms 348 KB Output is correct
9 Correct 0 ms 344 KB Output is correct
10 Correct 1 ms 344 KB Output is correct
11 Correct 12 ms 348 KB Output is correct
12 Correct 25 ms 600 KB Output is correct
13 Correct 50 ms 600 KB Output is correct
14 Correct 62 ms 1368 KB Output is correct
15 Correct 1 ms 344 KB Output is correct
16 Correct 0 ms 344 KB Output is correct
17 Correct 0 ms 344 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 344 KB Output is correct
3 Execution timed out 3039 ms 17232 KB Time limit exceeded
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 221 ms 28528 KB Output is correct
3 Correct 173 ms 28444 KB Output is correct
4 Correct 204 ms 28496 KB Output is correct
5 Correct 149 ms 21844 KB Output is correct
6 Correct 59 ms 5712 KB Output is correct
7 Correct 100 ms 10836 KB Output is correct
8 Correct 176 ms 25680 KB Output is correct
9 Correct 156 ms 22864 KB Output is correct
10 Correct 46 ms 6080 KB Output is correct
11 Correct 103 ms 14416 KB Output is correct
12 Correct 224 ms 28752 KB Output is correct
13 Correct 176 ms 28668 KB Output is correct
14 Correct 185 ms 28572 KB Output is correct
15 Correct 143 ms 21728 KB Output is correct
16 Correct 62 ms 4688 KB Output is correct
17 Correct 90 ms 11020 KB Output is correct
18 Correct 204 ms 28704 KB Output is correct
19 Correct 178 ms 28780 KB Output is correct
20 Correct 178 ms 28752 KB Output is correct
21 Correct 164 ms 25684 KB Output is correct
22 Correct 162 ms 23120 KB Output is correct
23 Correct 47 ms 6072 KB Output is correct
24 Correct 104 ms 14416 KB Output is correct
25 Correct 210 ms 28900 KB Output is correct
26 Correct 186 ms 28752 KB Output is correct
27 Correct 182 ms 28752 KB Output is correct
28 Correct 140 ms 21584 KB Output is correct
29 Correct 57 ms 4692 KB Output is correct
30 Correct 91 ms 11140 KB Output is correct
31 Correct 205 ms 28892 KB Output is correct
32 Correct 189 ms 28748 KB Output is correct
33 Correct 178 ms 28752 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 6 ms 344 KB Output is correct
2 Correct 30 ms 600 KB Output is correct
3 Correct 8 ms 600 KB Output is correct
4 Correct 8 ms 348 KB Output is correct
5 Correct 37 ms 600 KB Output is correct
6 Correct 0 ms 344 KB Output is correct
7 Correct 0 ms 344 KB Output is correct
8 Correct 1 ms 348 KB Output is correct
9 Correct 0 ms 344 KB Output is correct
10 Correct 1 ms 344 KB Output is correct
11 Correct 12 ms 348 KB Output is correct
12 Correct 25 ms 600 KB Output is correct
13 Correct 50 ms 600 KB Output is correct
14 Correct 62 ms 1368 KB Output is correct
15 Correct 1 ms 344 KB Output is correct
16 Correct 0 ms 344 KB Output is correct
17 Correct 0 ms 344 KB Output is correct
18 Execution timed out 3026 ms 14940 KB Time limit exceeded
19 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 6 ms 344 KB Output is correct
2 Correct 30 ms 600 KB Output is correct
3 Correct 8 ms 600 KB Output is correct
4 Correct 8 ms 348 KB Output is correct
5 Correct 37 ms 600 KB Output is correct
6 Correct 0 ms 344 KB Output is correct
7 Correct 0 ms 344 KB Output is correct
8 Correct 1 ms 348 KB Output is correct
9 Correct 0 ms 344 KB Output is correct
10 Correct 1 ms 344 KB Output is correct
11 Correct 12 ms 348 KB Output is correct
12 Correct 25 ms 600 KB Output is correct
13 Correct 50 ms 600 KB Output is correct
14 Correct 62 ms 1368 KB Output is correct
15 Correct 1 ms 344 KB Output is correct
16 Correct 0 ms 344 KB Output is correct
17 Correct 0 ms 344 KB Output is correct
18 Execution timed out 3026 ms 14940 KB Time limit exceeded
19 Halted 0 ms 0 KB -