답안 #263506

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
263506 2020-08-13T18:19:53 Z Kastanda 무지개나라 (APIO17_rainbow) C++11
100 / 100
1010 ms 159212 KB
// M
#include<bits/stdc++.h>
#include "rainbow.h"
#define lc (id << 1)
#define rc (lc ^ 1)
#define md ((l + r) >> 1)
using namespace std;
const int N = 200005;
int n, m;
vector < int > V[3][N], VS[3][N * 4], R[2][N], C[2][N];
vector < pair < int , int > > A;
map < int , int > MP[N];
inline int Count(vector < int > &vec, int l, int r)
{
        // [l, r)
        return (int)(lower_bound(vec.begin(), vec.end(), r) - lower_bound(vec.begin(), vec.end(), l));
}
void Build(int id = 1, int l = 1, int r = n + 1)
{
        if (r - l < 2)
        {
                for (int w = 0; w <= 2; w ++)
                {
                        VS[w][id] = V[w][l];
                        sort(VS[w][id].begin(), VS[w][id].end());
                }
                return ;
        }
        Build(lc, l, md);
        Build(rc, md, r);
        for (int w = 0; w <= 2; w ++)
                merge(VS[w][lc].begin(), VS[w][lc].end(), VS[w][rc].begin(), VS[w][rc].end(), back_inserter(VS[w][id]));
}
int Get(int w, int le, int ri, int lq, int rq, int id = 1, int l = 1, int r = n + 1)
{
        if (ri <= l || r <= le)
                return 0;
        if (le <= l && r <= ri)
                return Count(VS[w][id], lq, rq);
        return Get(w, le, ri, lq, rq, lc, l, md) + Get(w, le, ri, lq, rq, rc, md, r);
}
void init(int _n, int _m, int sta, int stb, int k, char * S)
{
        n = _n; m = _m;
        int nwa = sta, nwb = stb;
        A.push_back(make_pair(nwa, nwb));
        for (int i = 0; i < k; i ++)
        {
                if (S[i] == 'N') nwa --;
                if (S[i] == 'S') nwa ++;
                if (S[i] == 'W') nwb --;
                if (S[i] == 'E') nwb ++;
                A.push_back(make_pair(nwa, nwb));
        }
        sort(A.begin(), A.end());
        A.resize(unique(A.begin(), A.end()) - A.begin());
        for (auto a : A)
                MP[a.first][a.second] = 1;
        // w = 0 is for vertices ..
        for (auto a : A)
                V[0][a.first].push_back(a.second);
        // w = 1 is for edges ..
        for (auto a : A)
        {
                // South :
                if (MP[a.first + 1][a.second])
                        V[1][a.first].push_back(a.second),
                        C[1][a.second].push_back(a.first);
                // East :
                if (MP[a.first][a.second + 1])
                        V[1][a.first].push_back(a.second),
                        R[1][a.first].push_back(a.second);
                // South-East :
                if (!MP[a.first][a.second + 1] && !MP[a.first + 1][a.second] && MP[a.first + 1][a.second + 1])
                        V[1][a.first].push_back(a.second);
                // South-West :
                if (!MP[a.first][a.second - 1] && !MP[a.first + 1][a.second] && MP[a.first + 1][a.second - 1])
                        V[1][a.first].push_back(a.second - 1);
                // w = 2 is for squares ..
                if (MP[a.first + 1][a.second] && MP[a.first][a.second + 1] && MP[a.first + 1][a.second + 1])
                        V[2][a.first].push_back(a.second);
        }
        Build();
        for (auto a : A)
                R[0][a.first].push_back(a.second),
                C[0][a.second].push_back(a.first);
        for (int i = 1; i <= n; i ++)
                for (int w = 0; w <= 1; w ++)
                        sort(R[w][i].begin(), R[w][i].end());
        for (int i = 1; i <= m; i ++)
                for (int w = 0; w <= 1; w ++)
                        sort(C[w][i].begin(), C[w][i].end());
}
int colour(int lx, int ly, int rx, int ry)
{
        // Note : if no river cell is on the border, then c = 2.
        // v - e + f = 1 + c  ~~~>  f = e - v + 1 + c
        // sq : number of 2*2 squares
        // Then the answer is f-1 - sq
        int v = Get(0, lx, rx + 1, ly, ry + 1);

        if (v == 0) // No river cell
                return 1;

        v += (rx - lx + 1 + ry - ly + 1) * 2 + 4;

        int e = Get(1, lx, rx, ly, ry) + (rx - lx + 1 + ry - ly + 1) * 2 + 4;

        int stamp = e;

        e += Count(R[0][lx], ly, ry + 1);
        e += Count(R[0][rx], ly, ry + 1);
        e += Count(C[0][ly], lx, rx + 1);
        e += Count(C[0][ry], lx, rx + 1);

        int c = 1;
        if (e == stamp) // There is no border river cell
                c = 2;

        e += Count(R[1][rx], ly, ry);
        e += Count(C[1][ry], lx, rx);

        int sq = MP[lx][ly] + MP[lx][ry] + MP[rx][ly] + MP[rx][ry];

        sq += Get(2, lx, rx, ly, ry);
        sq += Count(R[1][lx], ly, ry);
        sq += Count(R[1][rx], ly, ry);
        sq += Count(C[1][ly], lx, rx);
        sq += Count(C[1][ry], lx, rx);

        /*printf("v is : %d\n", v);
        printf("e is : %d\n", e);
        printf("c is : %d\n", c);
        printf("sq is : %d\n", sq);*/

        int f = e - v + 1 + c;

        //printf("f is : %d\n", f);

        return f-1 - sq;

}
# 결과 실행 시간 메모리 Grader output
1 Correct 66 ms 99064 KB Output is correct
2 Correct 67 ms 99192 KB Output is correct
3 Correct 66 ms 99064 KB Output is correct
4 Correct 67 ms 99064 KB Output is correct
5 Correct 69 ms 99320 KB Output is correct
6 Correct 64 ms 98936 KB Output is correct
7 Correct 64 ms 98936 KB Output is correct
8 Correct 64 ms 98936 KB Output is correct
9 Correct 63 ms 98936 KB Output is correct
10 Correct 64 ms 98936 KB Output is correct
11 Correct 69 ms 99064 KB Output is correct
12 Correct 68 ms 99192 KB Output is correct
13 Correct 75 ms 99320 KB Output is correct
14 Correct 74 ms 99360 KB Output is correct
15 Correct 64 ms 98936 KB Output is correct
16 Correct 65 ms 98936 KB Output is correct
17 Correct 65 ms 99064 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 65 ms 98936 KB Output is correct
2 Correct 65 ms 99064 KB Output is correct
3 Correct 437 ms 114124 KB Output is correct
4 Correct 685 ms 124056 KB Output is correct
5 Correct 659 ms 123140 KB Output is correct
6 Correct 448 ms 116588 KB Output is correct
7 Correct 504 ms 114792 KB Output is correct
8 Correct 241 ms 106348 KB Output is correct
9 Correct 682 ms 121140 KB Output is correct
10 Correct 643 ms 121068 KB Output is correct
11 Correct 483 ms 116716 KB Output is correct
12 Correct 284 ms 115048 KB Output is correct
13 Correct 296 ms 116328 KB Output is correct
14 Correct 302 ms 116492 KB Output is correct
15 Correct 290 ms 113388 KB Output is correct
16 Correct 461 ms 116832 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 64 ms 98936 KB Output is correct
2 Correct 201 ms 129004 KB Output is correct
3 Correct 249 ms 151148 KB Output is correct
4 Correct 219 ms 142312 KB Output is correct
5 Correct 189 ms 132712 KB Output is correct
6 Correct 115 ms 110316 KB Output is correct
7 Correct 145 ms 120360 KB Output is correct
8 Correct 164 ms 114280 KB Output is correct
9 Correct 164 ms 113640 KB Output is correct
10 Correct 109 ms 108528 KB Output is correct
11 Correct 135 ms 115180 KB Output is correct
12 Correct 197 ms 129128 KB Output is correct
13 Correct 246 ms 150888 KB Output is correct
14 Correct 226 ms 142312 KB Output is correct
15 Correct 191 ms 132716 KB Output is correct
16 Correct 111 ms 108524 KB Output is correct
17 Correct 149 ms 120812 KB Output is correct
18 Correct 175 ms 128364 KB Output is correct
19 Correct 216 ms 139496 KB Output is correct
20 Correct 222 ms 140012 KB Output is correct
21 Correct 163 ms 114284 KB Output is correct
22 Correct 158 ms 113644 KB Output is correct
23 Correct 107 ms 108524 KB Output is correct
24 Correct 129 ms 115176 KB Output is correct
25 Correct 202 ms 129128 KB Output is correct
26 Correct 254 ms 150996 KB Output is correct
27 Correct 215 ms 142316 KB Output is correct
28 Correct 190 ms 132712 KB Output is correct
29 Correct 113 ms 108524 KB Output is correct
30 Correct 153 ms 120688 KB Output is correct
31 Correct 177 ms 128436 KB Output is correct
32 Correct 218 ms 139580 KB Output is correct
33 Correct 211 ms 140008 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 66 ms 99064 KB Output is correct
2 Correct 67 ms 99192 KB Output is correct
3 Correct 66 ms 99064 KB Output is correct
4 Correct 67 ms 99064 KB Output is correct
5 Correct 69 ms 99320 KB Output is correct
6 Correct 64 ms 98936 KB Output is correct
7 Correct 64 ms 98936 KB Output is correct
8 Correct 64 ms 98936 KB Output is correct
9 Correct 63 ms 98936 KB Output is correct
10 Correct 64 ms 98936 KB Output is correct
11 Correct 69 ms 99064 KB Output is correct
12 Correct 68 ms 99192 KB Output is correct
13 Correct 75 ms 99320 KB Output is correct
14 Correct 74 ms 99360 KB Output is correct
15 Correct 64 ms 98936 KB Output is correct
16 Correct 65 ms 98936 KB Output is correct
17 Correct 65 ms 99064 KB Output is correct
18 Correct 1010 ms 127212 KB Output is correct
19 Correct 206 ms 101952 KB Output is correct
20 Correct 184 ms 100216 KB Output is correct
21 Correct 184 ms 100984 KB Output is correct
22 Correct 182 ms 101116 KB Output is correct
23 Correct 191 ms 101624 KB Output is correct
24 Correct 252 ms 100344 KB Output is correct
25 Correct 230 ms 101368 KB Output is correct
26 Correct 231 ms 101752 KB Output is correct
27 Correct 480 ms 118636 KB Output is correct
28 Correct 684 ms 118736 KB Output is correct
29 Correct 573 ms 121200 KB Output is correct
30 Correct 701 ms 129520 KB Output is correct
31 Correct 67 ms 98936 KB Output is correct
32 Correct 716 ms 111048 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 66 ms 99064 KB Output is correct
2 Correct 67 ms 99192 KB Output is correct
3 Correct 66 ms 99064 KB Output is correct
4 Correct 67 ms 99064 KB Output is correct
5 Correct 69 ms 99320 KB Output is correct
6 Correct 64 ms 98936 KB Output is correct
7 Correct 64 ms 98936 KB Output is correct
8 Correct 64 ms 98936 KB Output is correct
9 Correct 63 ms 98936 KB Output is correct
10 Correct 64 ms 98936 KB Output is correct
11 Correct 69 ms 99064 KB Output is correct
12 Correct 68 ms 99192 KB Output is correct
13 Correct 75 ms 99320 KB Output is correct
14 Correct 74 ms 99360 KB Output is correct
15 Correct 64 ms 98936 KB Output is correct
16 Correct 65 ms 98936 KB Output is correct
17 Correct 65 ms 99064 KB Output is correct
18 Correct 1010 ms 127212 KB Output is correct
19 Correct 206 ms 101952 KB Output is correct
20 Correct 184 ms 100216 KB Output is correct
21 Correct 184 ms 100984 KB Output is correct
22 Correct 182 ms 101116 KB Output is correct
23 Correct 191 ms 101624 KB Output is correct
24 Correct 252 ms 100344 KB Output is correct
25 Correct 230 ms 101368 KB Output is correct
26 Correct 231 ms 101752 KB Output is correct
27 Correct 480 ms 118636 KB Output is correct
28 Correct 684 ms 118736 KB Output is correct
29 Correct 573 ms 121200 KB Output is correct
30 Correct 701 ms 129520 KB Output is correct
31 Correct 67 ms 98936 KB Output is correct
32 Correct 716 ms 111048 KB Output is correct
33 Correct 201 ms 129004 KB Output is correct
34 Correct 249 ms 151148 KB Output is correct
35 Correct 219 ms 142312 KB Output is correct
36 Correct 189 ms 132712 KB Output is correct
37 Correct 115 ms 110316 KB Output is correct
38 Correct 145 ms 120360 KB Output is correct
39 Correct 164 ms 114280 KB Output is correct
40 Correct 164 ms 113640 KB Output is correct
41 Correct 109 ms 108528 KB Output is correct
42 Correct 135 ms 115180 KB Output is correct
43 Correct 197 ms 129128 KB Output is correct
44 Correct 246 ms 150888 KB Output is correct
45 Correct 226 ms 142312 KB Output is correct
46 Correct 191 ms 132716 KB Output is correct
47 Correct 111 ms 108524 KB Output is correct
48 Correct 149 ms 120812 KB Output is correct
49 Correct 175 ms 128364 KB Output is correct
50 Correct 216 ms 139496 KB Output is correct
51 Correct 222 ms 140012 KB Output is correct
52 Correct 163 ms 114284 KB Output is correct
53 Correct 158 ms 113644 KB Output is correct
54 Correct 107 ms 108524 KB Output is correct
55 Correct 129 ms 115176 KB Output is correct
56 Correct 202 ms 129128 KB Output is correct
57 Correct 254 ms 150996 KB Output is correct
58 Correct 215 ms 142316 KB Output is correct
59 Correct 190 ms 132712 KB Output is correct
60 Correct 113 ms 108524 KB Output is correct
61 Correct 153 ms 120688 KB Output is correct
62 Correct 177 ms 128436 KB Output is correct
63 Correct 218 ms 139580 KB Output is correct
64 Correct 211 ms 140008 KB Output is correct
65 Correct 786 ms 121200 KB Output is correct
66 Correct 801 ms 122476 KB Output is correct
67 Correct 517 ms 114032 KB Output is correct
68 Correct 618 ms 129900 KB Output is correct
69 Correct 458 ms 137236 KB Output is correct
70 Correct 624 ms 159212 KB Output is correct
71 Correct 431 ms 147088 KB Output is correct
72 Correct 446 ms 138860 KB Output is correct
73 Correct 340 ms 115400 KB Output is correct
74 Correct 322 ms 125432 KB Output is correct
75 Correct 313 ms 132076 KB Output is correct
76 Correct 575 ms 149228 KB Output is correct
77 Correct 893 ms 157292 KB Output is correct
78 Correct 437 ms 114124 KB Output is correct
79 Correct 685 ms 124056 KB Output is correct
80 Correct 659 ms 123140 KB Output is correct
81 Correct 448 ms 116588 KB Output is correct
82 Correct 504 ms 114792 KB Output is correct
83 Correct 241 ms 106348 KB Output is correct
84 Correct 682 ms 121140 KB Output is correct
85 Correct 643 ms 121068 KB Output is correct
86 Correct 483 ms 116716 KB Output is correct
87 Correct 284 ms 115048 KB Output is correct
88 Correct 296 ms 116328 KB Output is correct
89 Correct 302 ms 116492 KB Output is correct
90 Correct 290 ms 113388 KB Output is correct
91 Correct 461 ms 116832 KB Output is correct