답안 #391785

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
391785 2021-04-19T20:08:26 Z MarcoMeijer 무지개나라 (APIO17_rainbow) C++14
35 / 100
3000 ms 55704 KB
#include "rainbow.h"
#include <bits/stdc++.h>
using namespace std;

// macros
typedef long long ll;
typedef long double ld;
typedef pair<int, int> ii;
typedef pair<ll, ll> lll;
typedef tuple<int, int, int> iii;
typedef vector<int> vi;
typedef vector<ii> vii;
typedef vector<iii> viii;
typedef vector<ll> vll;
typedef vector<lll> vlll;
#define REP(a,b,c) for(int a=int(b); a<int(c); a++)
#define RE(a,c) REP(a,0,c)
#define RE1(a,c) REP(a,1,c+1)
#define REI(a,b,c) REP(a,b,c+1)
#define REV(a,b,c) for(int a=int(c-1); a>=int(b); a--)
#define FOR(a,b) for(auto& a : b)
#define all(a) a.begin(), a.end()
#define INF 1e9
#define EPS 1e-9
#define pb push_back
#define popb pop_back
#define fi first
#define se second
#define sz size()

const int MX = (1<<23);
const int N = (1<<19);

int R, C, sr, sc, m;
set<ii> blue;
set<ii> points;
set<ii> edges;
int minR, maxR, minC, maxC;

struct QuadTree {
    int tot[MX];
    int child[MX][4];
    int nxt=1;
    QuadTree() {
        RE(i,N) tot[i]=0;
        RE(i,N) RE(j,4) child[i][j] = -1;
    }

    void add(int x, int y, int val, int l=0, int r=N-1, int u=0, int d=N-1, int p=0) {
        tot[p] += val;
        if(l == r)
            return;
        int mh = (l+r)/2;
        int mv = (u+d)/2;
        int cd = 0;
        if(x <= mh) cd += 1, r=mh;
        else l=mh+1;
        if(y <= mv) cd += 2, d=mv;
        else u=mv+1;
        if(child[p][cd] == -1) child[p][cd] = nxt++;
        add(x,y,val,l,r,u,d,child[p][cd]);
    }
    int get(int a, int b, int x, int y, int l=0, int r=N-1, int u=0, int d=N-1, int p=0) {
        if(p == -1) return 0;
        if(b < l || a > r || y < u || x > d) return 0;
        if(a <= l && b >= r && x <= u && y >= d) return tot[p];
        int mh = (l+r)/2;
        int mv = (u+d)/2;
        int res = 0;
        res += get(a,b,x,y, mh+1, r , mv+1, d , child[p][0]);
        res += get(a,b,x,y, l   , mh, mv+1, d , child[p][1]);
        res += get(a,b,x,y, mh+1, r , u   , mv, child[p][2]);
        res += get(a,b,x,y, l   , mh, u   , mv, child[p][3]);
        return res;
    }
} blueCells, bluePoints, blueLandEdgesH, blueLandEdgesV;

void init(int _R, int _C, int _sr, int _sc, int M, char *S) {
    R=_R; C=_C; sr=_sr; sc=_sc;
    minR=maxR=sr;
    minC=maxC=sc;
    RE(i,M) {
        blue.insert({sc,sr});
        if(S[i] == 'N') sr--;
        if(S[i] == 'S') sr++;
        if(S[i] == 'E') sc++;
        if(S[i] == 'W') sc--;
    }
    blue.insert({sc,sr});

    FOR(p,blue) {
        minR = min(minR, p.se);
        minC = min(minC, p.fi);
        maxR = max(maxR, p.se);
        maxC = max(maxC, p.fi);
        blueCells.add(p.fi,p.se,1);
        points.insert({p.fi  ,p.se  });
        points.insert({p.fi  ,p.se+1});
        points.insert({p.fi+1,p.se  });
        points.insert({p.fi+1,p.se+1});

        if(!blue.count({p.fi-1,p.se  })) blueLandEdgesV.add(p.fi  , p.se  , 1);
        blueLandEdgesV.add(p.fi+1, p.se  , 1);
        if(!blue.count({p.fi  ,p.se-1})) blueLandEdgesH.add(p.fi  , p.se  , 1);
        blueLandEdgesH.add(p.fi  , p.se+1, 1);
    }

    FOR(p,points) {
        bluePoints.add(p.fi,p.se,1);
    }
}

int colour(int ar, int ac, int br, int bc) {
    int blueCellsCnt  = blueCells .get(ac  ,bc,ar  ,br);
    int bluePointsCnt = bluePoints.get(ac+1,bc,ar+1,br);
    int blueLandEdges = blueLandEdgesH.get(ac,bc,ar+1,br) + blueLandEdgesV.get(ac+1,bc,ar,br);
    int W = bc - ac + 1;
    int H = br - ar + 1;
    int V = W*H - blueCellsCnt;
    int F = (W-1)*(H-1) - bluePointsCnt + 1;
    int E = (W-1)*H + (H-1)*W - blueLandEdges;

    if(ar < minR && maxR < br && ac < minC && maxC < bc)
        F++;

    return V - E + F - 1;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 29 ms 41420 KB Output is correct
2 Correct 33 ms 41412 KB Output is correct
3 Correct 32 ms 41420 KB Output is correct
4 Correct 31 ms 41352 KB Output is correct
5 Correct 34 ms 41504 KB Output is correct
6 Correct 22 ms 41292 KB Output is correct
7 Correct 23 ms 41388 KB Output is correct
8 Correct 23 ms 41312 KB Output is correct
9 Correct 24 ms 41388 KB Output is correct
10 Correct 23 ms 41328 KB Output is correct
11 Correct 30 ms 41420 KB Output is correct
12 Correct 31 ms 41420 KB Output is correct
13 Correct 36 ms 41496 KB Output is correct
14 Correct 39 ms 41624 KB Output is correct
15 Correct 23 ms 41368 KB Output is correct
16 Correct 23 ms 41336 KB Output is correct
17 Correct 23 ms 41328 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 23 ms 41336 KB Output is correct
2 Correct 23 ms 41328 KB Output is correct
3 Execution timed out 3077 ms 49876 KB Time limit exceeded
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 23 ms 41368 KB Output is correct
2 Correct 216 ms 55572 KB Output is correct
3 Correct 220 ms 55660 KB Output is correct
4 Correct 228 ms 55616 KB Output is correct
5 Correct 167 ms 52112 KB Output is correct
6 Correct 66 ms 44100 KB Output is correct
7 Correct 102 ms 46836 KB Output is correct
8 Correct 168 ms 54052 KB Output is correct
9 Correct 157 ms 52684 KB Output is correct
10 Correct 63 ms 44352 KB Output is correct
11 Correct 110 ms 48452 KB Output is correct
12 Correct 215 ms 55656 KB Output is correct
13 Correct 223 ms 55620 KB Output is correct
14 Correct 227 ms 55700 KB Output is correct
15 Correct 167 ms 52024 KB Output is correct
16 Correct 59 ms 43588 KB Output is correct
17 Correct 102 ms 46792 KB Output is correct
18 Correct 202 ms 55604 KB Output is correct
19 Correct 226 ms 55668 KB Output is correct
20 Correct 226 ms 55584 KB Output is correct
21 Correct 179 ms 54212 KB Output is correct
22 Correct 163 ms 52624 KB Output is correct
23 Correct 61 ms 44224 KB Output is correct
24 Correct 112 ms 48364 KB Output is correct
25 Correct 215 ms 55632 KB Output is correct
26 Correct 232 ms 55580 KB Output is correct
27 Correct 225 ms 55648 KB Output is correct
28 Correct 171 ms 52120 KB Output is correct
29 Correct 60 ms 43640 KB Output is correct
30 Correct 102 ms 46788 KB Output is correct
31 Correct 199 ms 55664 KB Output is correct
32 Correct 233 ms 55704 KB Output is correct
33 Correct 232 ms 55684 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 29 ms 41420 KB Output is correct
2 Correct 33 ms 41412 KB Output is correct
3 Correct 32 ms 41420 KB Output is correct
4 Correct 31 ms 41352 KB Output is correct
5 Correct 34 ms 41504 KB Output is correct
6 Correct 22 ms 41292 KB Output is correct
7 Correct 23 ms 41388 KB Output is correct
8 Correct 23 ms 41312 KB Output is correct
9 Correct 24 ms 41388 KB Output is correct
10 Correct 23 ms 41328 KB Output is correct
11 Correct 30 ms 41420 KB Output is correct
12 Correct 31 ms 41420 KB Output is correct
13 Correct 36 ms 41496 KB Output is correct
14 Correct 39 ms 41624 KB Output is correct
15 Correct 23 ms 41368 KB Output is correct
16 Correct 23 ms 41336 KB Output is correct
17 Correct 23 ms 41328 KB Output is correct
18 Execution timed out 3079 ms 49160 KB Time limit exceeded
19 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 29 ms 41420 KB Output is correct
2 Correct 33 ms 41412 KB Output is correct
3 Correct 32 ms 41420 KB Output is correct
4 Correct 31 ms 41352 KB Output is correct
5 Correct 34 ms 41504 KB Output is correct
6 Correct 22 ms 41292 KB Output is correct
7 Correct 23 ms 41388 KB Output is correct
8 Correct 23 ms 41312 KB Output is correct
9 Correct 24 ms 41388 KB Output is correct
10 Correct 23 ms 41328 KB Output is correct
11 Correct 30 ms 41420 KB Output is correct
12 Correct 31 ms 41420 KB Output is correct
13 Correct 36 ms 41496 KB Output is correct
14 Correct 39 ms 41624 KB Output is correct
15 Correct 23 ms 41368 KB Output is correct
16 Correct 23 ms 41336 KB Output is correct
17 Correct 23 ms 41328 KB Output is correct
18 Execution timed out 3079 ms 49160 KB Time limit exceeded
19 Halted 0 ms 0 KB -