답안 #487716

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
487716 2021-11-16T12:46:19 Z leaked 무지개나라 (APIO17_rainbow) C++14
11 / 100
201 ms 12688 KB
#include "rainbow.h"
#include <bits/stdc++.h>

#define f first
#define s second
#define vec vector
#define pb push_back
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
#define pw(x) (1LL<<(x))
#define sz(x) (int)(x).size()
#define m_p make_pair
#define fast_iati ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);

using namespace std;

template<class T> bool umin(T &a,const  T &b){return (a>b?a=b,1:0);}
template<class T> bool umax(T &a,const  T &b){return (a<b?a=b,1:0);}
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll>pll;
const int N=200'000;
int n,m;
struct dsu{
    int p[N],sz[N];
    void make(int v){
        p[v]=v;
        sz[v]=1;
    }
    int get(int v){
        return p[v]=(p[v]!=v?get(p[v]):v);
    }
    bool mg(int a,int b){
        a=get(a),b=get(b);
        if(a==b) return 0;
        if(sz[a]>sz[b]) swap(a,b);
        p[a]=b;sz[b]+=sz[a];
        return 1;
    }
};
dsu in;
map<pii,int> plased;
bool is[51][51];
char dx[4]={'W','E','N','S'};
int tx[4]={0,0,-1,1};
int ty[4]={-1,1,0,0};
vec<pii> go[2];
vec<int> cl[2];
void init(int R, int C, int sr, int sc, int M, char *S) {
    n=R,m=C;
    --sr;--sc;
    plased[{sr,sc}]=1;
    if(n<=50 && m<=50)
        is[sr][sc]=1;
    if(n<=2)
        cl[sr].pb(sc);
    for(int i=0;i<M;i++){
//        cout<<"P "<<S[i]<<endl;
        for(int j=0;j<4;j++){
            if(dx[j]==S[i]){
                sr+=tx[j];sc+=ty[j];
//                cout<<"E "<<endl;
            }
        }
        plased[{sr,sc}]=1;
//        go[sr].pb
        if(n<=2)
            cl[sr].pb(sc);
//        cout<<"ALO "<<sr+1<<' '<<sc+1<<endl;
        if(n<=50 && m<=50)
            is[sr][sc]=1;
    }
    if(n<=50 && m<=50){

    }
    else if(n==2){
        for(int i=0;i<2;i++){
            vec<pii> wow;
            int last=-1;
            sort(all(cl[i]));
            for(auto &z : cl[i]){
                if(z-last-1>=0)
                   wow.pb({last+1,z-1});
                last=z;
            }
            go[i]=wow;
        }
    }
    else{

    }
}
int ask1(int x,int x1,int y,int y1){
//    if(x1==y1 || y==y1) return 0;
//    --x1;--y1;
    --x;--x1;--y;--y1;
    for(int i=x;i<=x1;i++){
        for(int j=y;j<=y1;j++){
            if(!is[i][j]){
                in.make(i*m+j);
//                cout<<"IN "<<i<<' '<<j<<endl;
            }
        }
    }

    int ans=0;
    for(int i=x;i<=x1;i++){
        for(int j=y;j<=y1;j++){
            if(is[i][j]) continue;
//            cout<<"N "<<endl;
            for(int t=0;t<4;t++){
                int ni=i+tx[t],nj=j+ty[t];
                if(ni>=x && ni<=x1 && nj>=y && nj<=y1 && !is[ni][nj])
                    in.mg(i*m+j,ni*m+nj);
            }
        }
    }
    for(int i=x;i<=x1;i++){
        for(int j=y;j<=y1;j++){
            if(is[i][j]) continue;
//            cout<<"HERE "<<i<<' '<<j<<' '<<endl;
            if(in.get(i*m+j)==(i*m+j))
                ans++;
        }
    }
    return ans;
}
int ask2(int x,int x1,int y,int y1){
    if(x==x1){
        auto l=lower_bound(all(go[x]),m_p(y,y-1));
        if(l!=go[x].begin() && prev(l)->s>=y) l--;
        int h=upper_bound(all(go[x]),m_p(y1+1,y1+1))-l;
        return h;
    }
    else{
        return ask2(0,0,y,y1)+ask2(1,1,y,y1)-(!plased[{0,y}] && !plased[{1,y}])-((!plased[{0,y1}] && !plased[{1,y1}]));
    }
}
int colour(int ar, int ac, int br, int bc) {
    if(n<=50 && m<=50)
        return ask1(ar,br,ac,bc);
    if(n==2)
        return ask2(ar,br,ac,bc);
    return 0;
}

# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 332 KB Output is correct
2 Correct 15 ms 332 KB Output is correct
3 Correct 51 ms 332 KB Output is correct
4 Correct 43 ms 340 KB Output is correct
5 Correct 14 ms 332 KB Output is correct
6 Correct 0 ms 204 KB Output is correct
7 Correct 0 ms 204 KB Output is correct
8 Correct 1 ms 204 KB Output is correct
9 Correct 1 ms 204 KB Output is correct
10 Correct 1 ms 204 KB Output is correct
11 Correct 41 ms 348 KB Output is correct
12 Correct 26 ms 376 KB Output is correct
13 Correct 20 ms 332 KB Output is correct
14 Correct 5 ms 388 KB Output is correct
15 Correct 0 ms 204 KB Output is correct
16 Correct 0 ms 204 KB Output is correct
17 Correct 0 ms 204 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
3 Incorrect 201 ms 12688 KB Output isn't correct
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 204 KB Output is correct
2 Incorrect 26 ms 6648 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 332 KB Output is correct
2 Correct 15 ms 332 KB Output is correct
3 Correct 51 ms 332 KB Output is correct
4 Correct 43 ms 340 KB Output is correct
5 Correct 14 ms 332 KB Output is correct
6 Correct 0 ms 204 KB Output is correct
7 Correct 0 ms 204 KB Output is correct
8 Correct 1 ms 204 KB Output is correct
9 Correct 1 ms 204 KB Output is correct
10 Correct 1 ms 204 KB Output is correct
11 Correct 41 ms 348 KB Output is correct
12 Correct 26 ms 376 KB Output is correct
13 Correct 20 ms 332 KB Output is correct
14 Correct 5 ms 388 KB Output is correct
15 Correct 0 ms 204 KB Output is correct
16 Correct 0 ms 204 KB Output is correct
17 Correct 0 ms 204 KB Output is correct
18 Incorrect 56 ms 4220 KB Output isn't correct
19 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 332 KB Output is correct
2 Correct 15 ms 332 KB Output is correct
3 Correct 51 ms 332 KB Output is correct
4 Correct 43 ms 340 KB Output is correct
5 Correct 14 ms 332 KB Output is correct
6 Correct 0 ms 204 KB Output is correct
7 Correct 0 ms 204 KB Output is correct
8 Correct 1 ms 204 KB Output is correct
9 Correct 1 ms 204 KB Output is correct
10 Correct 1 ms 204 KB Output is correct
11 Correct 41 ms 348 KB Output is correct
12 Correct 26 ms 376 KB Output is correct
13 Correct 20 ms 332 KB Output is correct
14 Correct 5 ms 388 KB Output is correct
15 Correct 0 ms 204 KB Output is correct
16 Correct 0 ms 204 KB Output is correct
17 Correct 0 ms 204 KB Output is correct
18 Incorrect 56 ms 4220 KB Output isn't correct
19 Halted 0 ms 0 KB -