답안 #263510

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
263510 2020-08-13T18:25:53 Z Kastanda 무지개나라 (APIO17_rainbow) C++11
100 / 100
1008 ms 103020 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], 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));
}
inline void Build()
{
        for (int w = 0; w <= 2; w ++)
                for (int i = 1; i <= n; i ++)
                        for (int a : V[w][i])
                                for (int j = i; j <= n; j += j & - i)
                                        VS[w][j].push_back(a);
        for (int w = 0; w <= 2; w ++)
                for (int i = 1; i <= n; i ++)
                        sort(VS[w][i].begin(), VS[w][i].end());
}
inline int Get(int w, int i, int lq, int rq)
{
        int rt = 0;
        for (; i; i -= i & - i)
                rt += Count(VS[w][i], lq, rq);
        return rt;
}
inline int Get(int w, int le, int ri, int lq, int rq)
{
        return Get(w, ri - 1, lq, rq) - Get(w, le - 1, lq, rq);
}
/*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 47 ms 56696 KB Output is correct
2 Correct 48 ms 56952 KB Output is correct
3 Correct 44 ms 56824 KB Output is correct
4 Correct 45 ms 56824 KB Output is correct
5 Correct 48 ms 56952 KB Output is correct
6 Correct 44 ms 56696 KB Output is correct
7 Correct 36 ms 56696 KB Output is correct
8 Correct 46 ms 56696 KB Output is correct
9 Correct 39 ms 56696 KB Output is correct
10 Correct 40 ms 56700 KB Output is correct
11 Correct 42 ms 56824 KB Output is correct
12 Correct 44 ms 56968 KB Output is correct
13 Correct 44 ms 56960 KB Output is correct
14 Correct 44 ms 57056 KB Output is correct
15 Correct 49 ms 56696 KB Output is correct
16 Correct 51 ms 56696 KB Output is correct
17 Correct 38 ms 56696 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 51 ms 56696 KB Output is correct
2 Correct 38 ms 56696 KB Output is correct
3 Correct 468 ms 72308 KB Output is correct
4 Correct 784 ms 81868 KB Output is correct
5 Correct 701 ms 80872 KB Output is correct
6 Correct 472 ms 74476 KB Output is correct
7 Correct 523 ms 72812 KB Output is correct
8 Correct 200 ms 64616 KB Output is correct
9 Correct 619 ms 78956 KB Output is correct
10 Correct 608 ms 78768 KB Output is correct
11 Correct 481 ms 74600 KB Output is correct
12 Correct 264 ms 72944 KB Output is correct
13 Correct 279 ms 74088 KB Output is correct
14 Correct 283 ms 74476 KB Output is correct
15 Correct 301 ms 71404 KB Output is correct
16 Correct 498 ms 74744 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 49 ms 56696 KB Output is correct
2 Correct 183 ms 78708 KB Output is correct
3 Correct 161 ms 93864 KB Output is correct
4 Correct 173 ms 88936 KB Output is correct
5 Correct 165 ms 81092 KB Output is correct
6 Correct 103 ms 64364 KB Output is correct
7 Correct 149 ms 69104 KB Output is correct
8 Correct 164 ms 71020 KB Output is correct
9 Correct 157 ms 70120 KB Output is correct
10 Correct 75 ms 61036 KB Output is correct
11 Correct 101 ms 66792 KB Output is correct
12 Correct 207 ms 78832 KB Output is correct
13 Correct 173 ms 93932 KB Output is correct
14 Correct 172 ms 88936 KB Output is correct
15 Correct 153 ms 81132 KB Output is correct
16 Correct 98 ms 63336 KB Output is correct
17 Correct 176 ms 72068 KB Output is correct
18 Correct 240 ms 82156 KB Output is correct
19 Correct 178 ms 87272 KB Output is correct
20 Correct 180 ms 88172 KB Output is correct
21 Correct 166 ms 71020 KB Output is correct
22 Correct 156 ms 70124 KB Output is correct
23 Correct 75 ms 61040 KB Output is correct
24 Correct 101 ms 66792 KB Output is correct
25 Correct 190 ms 78828 KB Output is correct
26 Correct 175 ms 93932 KB Output is correct
27 Correct 169 ms 88936 KB Output is correct
28 Correct 151 ms 81388 KB Output is correct
29 Correct 96 ms 63208 KB Output is correct
30 Correct 166 ms 71912 KB Output is correct
31 Correct 239 ms 82156 KB Output is correct
32 Correct 190 ms 87232 KB Output is correct
33 Correct 198 ms 88168 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 47 ms 56696 KB Output is correct
2 Correct 48 ms 56952 KB Output is correct
3 Correct 44 ms 56824 KB Output is correct
4 Correct 45 ms 56824 KB Output is correct
5 Correct 48 ms 56952 KB Output is correct
6 Correct 44 ms 56696 KB Output is correct
7 Correct 36 ms 56696 KB Output is correct
8 Correct 46 ms 56696 KB Output is correct
9 Correct 39 ms 56696 KB Output is correct
10 Correct 40 ms 56700 KB Output is correct
11 Correct 42 ms 56824 KB Output is correct
12 Correct 44 ms 56968 KB Output is correct
13 Correct 44 ms 56960 KB Output is correct
14 Correct 44 ms 57056 KB Output is correct
15 Correct 49 ms 56696 KB Output is correct
16 Correct 51 ms 56696 KB Output is correct
17 Correct 38 ms 56696 KB Output is correct
18 Correct 1008 ms 82216 KB Output is correct
19 Correct 192 ms 59640 KB Output is correct
20 Correct 165 ms 58216 KB Output is correct
21 Correct 175 ms 59000 KB Output is correct
22 Correct 177 ms 59000 KB Output is correct
23 Correct 183 ms 59576 KB Output is correct
24 Correct 232 ms 58232 KB Output is correct
25 Correct 205 ms 59256 KB Output is correct
26 Correct 193 ms 59420 KB Output is correct
27 Correct 414 ms 71660 KB Output is correct
28 Correct 589 ms 73964 KB Output is correct
29 Correct 521 ms 73452 KB Output is correct
30 Correct 782 ms 82916 KB Output is correct
31 Correct 45 ms 56824 KB Output is correct
32 Correct 648 ms 66056 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 47 ms 56696 KB Output is correct
2 Correct 48 ms 56952 KB Output is correct
3 Correct 44 ms 56824 KB Output is correct
4 Correct 45 ms 56824 KB Output is correct
5 Correct 48 ms 56952 KB Output is correct
6 Correct 44 ms 56696 KB Output is correct
7 Correct 36 ms 56696 KB Output is correct
8 Correct 46 ms 56696 KB Output is correct
9 Correct 39 ms 56696 KB Output is correct
10 Correct 40 ms 56700 KB Output is correct
11 Correct 42 ms 56824 KB Output is correct
12 Correct 44 ms 56968 KB Output is correct
13 Correct 44 ms 56960 KB Output is correct
14 Correct 44 ms 57056 KB Output is correct
15 Correct 49 ms 56696 KB Output is correct
16 Correct 51 ms 56696 KB Output is correct
17 Correct 38 ms 56696 KB Output is correct
18 Correct 1008 ms 82216 KB Output is correct
19 Correct 192 ms 59640 KB Output is correct
20 Correct 165 ms 58216 KB Output is correct
21 Correct 175 ms 59000 KB Output is correct
22 Correct 177 ms 59000 KB Output is correct
23 Correct 183 ms 59576 KB Output is correct
24 Correct 232 ms 58232 KB Output is correct
25 Correct 205 ms 59256 KB Output is correct
26 Correct 193 ms 59420 KB Output is correct
27 Correct 414 ms 71660 KB Output is correct
28 Correct 589 ms 73964 KB Output is correct
29 Correct 521 ms 73452 KB Output is correct
30 Correct 782 ms 82916 KB Output is correct
31 Correct 45 ms 56824 KB Output is correct
32 Correct 648 ms 66056 KB Output is correct
33 Correct 183 ms 78708 KB Output is correct
34 Correct 161 ms 93864 KB Output is correct
35 Correct 173 ms 88936 KB Output is correct
36 Correct 165 ms 81092 KB Output is correct
37 Correct 103 ms 64364 KB Output is correct
38 Correct 149 ms 69104 KB Output is correct
39 Correct 164 ms 71020 KB Output is correct
40 Correct 157 ms 70120 KB Output is correct
41 Correct 75 ms 61036 KB Output is correct
42 Correct 101 ms 66792 KB Output is correct
43 Correct 207 ms 78832 KB Output is correct
44 Correct 173 ms 93932 KB Output is correct
45 Correct 172 ms 88936 KB Output is correct
46 Correct 153 ms 81132 KB Output is correct
47 Correct 98 ms 63336 KB Output is correct
48 Correct 176 ms 72068 KB Output is correct
49 Correct 240 ms 82156 KB Output is correct
50 Correct 178 ms 87272 KB Output is correct
51 Correct 180 ms 88172 KB Output is correct
52 Correct 166 ms 71020 KB Output is correct
53 Correct 156 ms 70124 KB Output is correct
54 Correct 75 ms 61040 KB Output is correct
55 Correct 101 ms 66792 KB Output is correct
56 Correct 190 ms 78828 KB Output is correct
57 Correct 175 ms 93932 KB Output is correct
58 Correct 169 ms 88936 KB Output is correct
59 Correct 151 ms 81388 KB Output is correct
60 Correct 96 ms 63208 KB Output is correct
61 Correct 166 ms 71912 KB Output is correct
62 Correct 239 ms 82156 KB Output is correct
63 Correct 190 ms 87232 KB Output is correct
64 Correct 198 ms 88168 KB Output is correct
65 Correct 898 ms 75480 KB Output is correct
66 Correct 934 ms 76376 KB Output is correct
67 Correct 501 ms 64624 KB Output is correct
68 Correct 585 ms 78960 KB Output is correct
69 Correct 387 ms 84328 KB Output is correct
70 Correct 450 ms 99560 KB Output is correct
71 Correct 332 ms 90988 KB Output is correct
72 Correct 329 ms 84844 KB Output is correct
73 Correct 240 ms 68072 KB Output is correct
74 Correct 283 ms 73968 KB Output is correct
75 Correct 340 ms 83092 KB Output is correct
76 Correct 469 ms 94312 KB Output is correct
77 Correct 769 ms 103020 KB Output is correct
78 Correct 468 ms 72308 KB Output is correct
79 Correct 784 ms 81868 KB Output is correct
80 Correct 701 ms 80872 KB Output is correct
81 Correct 472 ms 74476 KB Output is correct
82 Correct 523 ms 72812 KB Output is correct
83 Correct 200 ms 64616 KB Output is correct
84 Correct 619 ms 78956 KB Output is correct
85 Correct 608 ms 78768 KB Output is correct
86 Correct 481 ms 74600 KB Output is correct
87 Correct 264 ms 72944 KB Output is correct
88 Correct 279 ms 74088 KB Output is correct
89 Correct 283 ms 74476 KB Output is correct
90 Correct 301 ms 71404 KB Output is correct
91 Correct 498 ms 74744 KB Output is correct