Submission #487710

# Submission time Handle Problem Language Result Execution time Memory
487710 2021-11-16T12:33:14 Z leaked Land of the Rainbow Gold (APIO17_rainbow) C++14
0 / 100
24 ms 6676 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 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*4;
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];
    }
};
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};
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;
    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;
//        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){

    }
    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;
            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 colour(int ar, int ac, int br, int bc) {
    if(n<=50 && m<=50)
        return ask1(ar,br,ac,bc);

    return 0;
}

Compilation message

rainbow.cpp: In member function 'bool dsu::mg(int, int)':
rainbow.cpp:36:21: warning: control reaches end of non-void function [-Wreturn-type]
   36 |         p[a]=b;sz[b]+=sz[a];
      |                ~~~~~^~~~~~~
# Verdict Execution time Memory Grader output
1 Runtime error 3 ms 592 KB Execution killed with signal 6
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 208 KB Output is correct
2 Runtime error 4 ms 592 KB Execution killed with signal 6
# Verdict Execution time Memory Grader output
1 Correct 0 ms 208 KB Output is correct
2 Incorrect 24 ms 6676 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 3 ms 592 KB Execution killed with signal 6
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 3 ms 592 KB Execution killed with signal 6
2 Halted 0 ms 0 KB -