답안 #106470

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
106470 2019-04-18T15:29:11 Z polyfish 무지개나라 (APIO17_rainbow) C++14
35 / 100
3000 ms 117280 KB
#include "rainbow.h"
#include <bits/stdc++.h>
using namespace std;

#define debug(x) cerr << #x << " = " << x << '\n';
#define BP() cerr << "OK!\n";
#define PR(A, n) {cerr << #A << " = "; for (int _=1; _<=n; ++_) cerr << A[_] << ' '; cerr << '\n';}
#define PR0(A, n) {cerr << #A << " = "; for (int _=0; _<n; ++_) cerr << A[_] << ' '; cerr << '\n';}
#define FILE_NAME "data"

const int X[] = {1, 0, -1, 0};
const int Y[] = {0, 1, 0, -1};
const int INF = 1e9;

int m, n, min_x, max_x, min_y, max_y;
vector<pair<int, int> > snake;
bool visited[52][52];

void init(int R, int C, int sr, int sc, int M, char *S) {
    m = R;
    n = C;
    max_x = max_y = -INF;
    min_x = min_y = INF;

    snake.resize(M+1);
    snake[0] = {sr, sc};
    for (int i=1; i<=M; ++i) {
        snake[i] = snake[i-1];
        if (S[i-1]=='N')
            --snake[i].first;
        else if (S[i-1]=='S')
            ++snake[i].first;
        else if (S[i-1]=='W')
            --snake[i].second;
        else
            ++snake[i].second;
    }

    sort(snake.begin(), snake.end());
    snake.resize(unique(snake.begin(), snake.end()) - snake.begin());
    for (auto p : snake) {
        min_x = min(min_x, p.first);
        max_x = max(max_x, p.first);
        min_y = min(min_y, p.second);
        max_y = max(max_y, p.second);
    }
}

void visit(int u, int v, int x1, int y1, int x2, int y2) {
    visited[u][v] = true;

    for (int i=0; i<4; ++i) {
        int p = u + X[i], q = v + Y[i];
        if (x1<=p && p<=x2 && y1<=q && q<=y2 && !visited[p][q])
            visit(p, q, x1, y1, x2, y2);
    }
}

int subtask1(int x1, int y1, int x2, int y2) {
    memset(visited, false, sizeof(visited));

    for (auto p : snake)
        visited[p.first][p.second] = true;

    int res = 0;

    for (int i=x1; i<=x2; ++i) {
        for (int j=y1; j<=y2; ++j) {
            if (!visited[i][j]) {
                ++res;
                visit(i, j, x1, y1, x2, y2);
            }
        }
    }

    return res;
}

int subtask3(int x1, int y1, int x2, int y2) {
    set<pair<int, int> > v;
    set<pair<pair<int, int>, pair<int, int> > > e;

    int res = 0;

    for (int i=x1; i<=x2+1; ++i) {
        v.insert({i, y1});
        v.insert({i, y2+1});
        if (i<=x2) {
            pair<int, int> tmp1(i, y1), tmp2(i+1, y1);
            e.insert({min(tmp1, tmp2), max(tmp1, tmp2)});
            pair<int, int> tmp3(i, y2+1), tmp4(i+1, y2+1);
            e.insert({min(tmp3, tmp4), max(tmp3, tmp4)});
        }
    }

    for (int i=y1; i<=y2+1; ++i) {
        v.insert({x1, i});
        v.insert({x2+1, i});
        if (i<=y2) {
            pair<int, int> tmp1(x1, i), tmp2(x1, i+1);
            e.insert({min(tmp1, tmp2), max(tmp1, tmp2)});
            pair<int, int> tmp3(x2+1, i), tmp4(x2+1, i+1);
            e.insert({min(tmp3, tmp4), max(tmp3, tmp4)});
        }
    }

    for (auto p : snake) {
        if (x1<=p.first && p.first<=x2 && y1<=p.second && p.second<=y2) {
            --res;
            for (int i=0; i<4; ++i) {
                v.insert(p);
                pair<int, int> tmp = p;
                p.first += X[i];
                p.second += Y[i];
                e.insert({min(p, tmp), max(p, tmp)});
            }
        }
    }
//    debug(v.size());
//    debug(e.size());

    res += (int)e.size() - (int)v.size() + 1;

    if (x1<min_x && max_x<x2 && y1<min_y && max_y<y2)
        ++res;

    return res;
}

int colour(int x1, int y1, int x2, int y2) {
    return subtask3(x1, y1, x2, y2);
//    if (m<=50 && n<=50)
//        return subtask1(x1, y1, x2, y2);
//    else
//        return subtask3(x1, y1, x2, y2);
}

# 결과 실행 시간 메모리 Grader output
1 Correct 27 ms 384 KB Output is correct
2 Correct 111 ms 512 KB Output is correct
3 Correct 46 ms 384 KB Output is correct
4 Correct 63 ms 512 KB Output is correct
5 Correct 143 ms 760 KB Output is correct
6 Correct 3 ms 256 KB Output is correct
7 Correct 2 ms 256 KB Output is correct
8 Correct 2 ms 384 KB Output is correct
9 Correct 2 ms 384 KB Output is correct
10 Correct 3 ms 384 KB Output is correct
11 Correct 99 ms 504 KB Output is correct
12 Correct 221 ms 564 KB Output is correct
13 Correct 344 ms 760 KB Output is correct
14 Correct 615 ms 768 KB Output is correct
15 Correct 2 ms 256 KB Output is correct
16 Correct 2 ms 256 KB Output is correct
17 Correct 3 ms 384 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 256 KB Output is correct
2 Correct 3 ms 384 KB Output is correct
3 Execution timed out 3032 ms 45264 KB Time limit exceeded
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 256 KB Output is correct
2 Correct 418 ms 48248 KB Output is correct
3 Correct 366 ms 48248 KB Output is correct
4 Correct 392 ms 51352 KB Output is correct
5 Correct 167 ms 25188 KB Output is correct
6 Correct 425 ms 55340 KB Output is correct
7 Correct 710 ms 83960 KB Output is correct
8 Correct 47 ms 6264 KB Output is correct
9 Correct 30 ms 3832 KB Output is correct
10 Correct 41 ms 2524 KB Output is correct
11 Correct 46 ms 6008 KB Output is correct
12 Correct 100 ms 13392 KB Output is correct
13 Correct 80 ms 13292 KB Output is correct
14 Correct 87 ms 13300 KB Output is correct
15 Correct 157 ms 13156 KB Output is correct
16 Correct 522 ms 44776 KB Output is correct
17 Correct 346 ms 40868 KB Output is correct
18 Correct 495 ms 55180 KB Output is correct
19 Correct 521 ms 62184 KB Output is correct
20 Correct 453 ms 56884 KB Output is correct
21 Correct 216 ms 26488 KB Output is correct
22 Correct 185 ms 23572 KB Output is correct
23 Correct 194 ms 28288 KB Output is correct
24 Correct 314 ms 41568 KB Output is correct
25 Correct 981 ms 117240 KB Output is correct
26 Correct 919 ms 117280 KB Output is correct
27 Correct 875 ms 117268 KB Output is correct
28 Correct 833 ms 110052 KB Output is correct
29 Correct 858 ms 93028 KB Output is correct
30 Correct 842 ms 98940 KB Output is correct
31 Correct 950 ms 117048 KB Output is correct
32 Correct 1032 ms 111728 KB Output is correct
33 Correct 1032 ms 111716 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 27 ms 384 KB Output is correct
2 Correct 111 ms 512 KB Output is correct
3 Correct 46 ms 384 KB Output is correct
4 Correct 63 ms 512 KB Output is correct
5 Correct 143 ms 760 KB Output is correct
6 Correct 3 ms 256 KB Output is correct
7 Correct 2 ms 256 KB Output is correct
8 Correct 2 ms 384 KB Output is correct
9 Correct 2 ms 384 KB Output is correct
10 Correct 3 ms 384 KB Output is correct
11 Correct 99 ms 504 KB Output is correct
12 Correct 221 ms 564 KB Output is correct
13 Correct 344 ms 760 KB Output is correct
14 Correct 615 ms 768 KB Output is correct
15 Correct 2 ms 256 KB Output is correct
16 Correct 2 ms 256 KB Output is correct
17 Correct 3 ms 384 KB Output is correct
18 Execution timed out 3046 ms 11488 KB Time limit exceeded
19 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 27 ms 384 KB Output is correct
2 Correct 111 ms 512 KB Output is correct
3 Correct 46 ms 384 KB Output is correct
4 Correct 63 ms 512 KB Output is correct
5 Correct 143 ms 760 KB Output is correct
6 Correct 3 ms 256 KB Output is correct
7 Correct 2 ms 256 KB Output is correct
8 Correct 2 ms 384 KB Output is correct
9 Correct 2 ms 384 KB Output is correct
10 Correct 3 ms 384 KB Output is correct
11 Correct 99 ms 504 KB Output is correct
12 Correct 221 ms 564 KB Output is correct
13 Correct 344 ms 760 KB Output is correct
14 Correct 615 ms 768 KB Output is correct
15 Correct 2 ms 256 KB Output is correct
16 Correct 2 ms 256 KB Output is correct
17 Correct 3 ms 384 KB Output is correct
18 Execution timed out 3046 ms 11488 KB Time limit exceeded
19 Halted 0 ms 0 KB -