Submission #402935

# Submission time Handle Problem Language Result Execution time Memory
402935 2021-05-12T14:38:51 Z teehandsome Land of the Rainbow Gold (APIO17_rainbow) C++11
11 / 100
22 ms 844 KB
#include "rainbow.h"
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define endl '\n'
#define INF 1e9+7
#define all(x) x.begin(),x.end()
using namespace std;
using namespace __gnu_pbds;
using ll=long long;
using pii=pair<int,int>;
using ppi=pair<int,pii>;
using oset=tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update>;

template<typename T>
void _print(vector<T> x) {cerr<<"{"; for(auto e:x) cerr<<e<<","; cerr<<"}";}
void _print(pii x) {cerr<<"{"<<x.first<<","<<x.second<<"}";}
template<typename T>
void _print(T x) {cerr<<x;}

void dbg() {cerr<<endl;}
template<typename Head,typename... Tail>
void dbg(Head H,Tail... T) {
    _print(H);
    if(sizeof...(T)) cerr<<",";
    else cerr<<"\"]";
    dbg(T...);
}
#define debug(...) cerr<<"["<<#__VA_ARGS__<<"]:[\"",dbg(__VA_ARGS__)

//mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

bool flag[51][51];
bool flag2[51][51];
int dm[4]={-1,0,1,0};
int dn[4]={0,1,0,-1};
char dir[4]={'N','E','S','W'};

void init(int R, int C, int sr, int sc, int M, char *S) {
    flag[sr][sc]=true;
    for(int i=0;i<M;i++) {
        for(int j=0;j<4;j++) {
            if(S[i]==dir[j]) {
                sr+=dm[j]; sc+=dn[j]; break;
            }
        }
        flag[sr][sc]=true;
    }
}

void bfs(int sm,int sn,int &ar,int &ac,int &br,int &bc) {
    queue<pii> q;
    q.push({sm,sn});
    while(!q.empty()) {
        pii cur=q.front(); q.pop();
        int M=cur.first,N=cur.second;
        flag2[M][N]=true;
        for(int i=0;i<4;i++) {
            int mm=M+dm[i],nn=N+dn[i];
            if(mm>=ar and mm<=br and nn>=ac and nn<=bc) {
                if(!flag2[mm][nn] and !flag[mm][nn]) {
                    flag2[mm][nn]=true;
                    q.push({mm,nn});
                }
            }
        }
    }
}

int colour(int ar, int ac, int br, int bc) {
    memset(flag2,false,sizeof(flag2));
    int ans=0;
    for(int i=ar;i<=br;i++) {
        for(int j=ac;j<=bc;j++) {
            if(flag[i][j] or flag2[i][j]) continue;
            bfs(i,j,ar,ac,br,bc); ans++;
        }
    }
    return ans;
}


# Verdict Execution time Memory Grader output
1 Correct 3 ms 204 KB Output is correct
2 Correct 9 ms 332 KB Output is correct
3 Correct 22 ms 332 KB Output is correct
4 Correct 22 ms 312 KB Output is correct
5 Correct 8 ms 292 KB Output is correct
6 Correct 1 ms 204 KB Output is correct
7 Correct 1 ms 296 KB Output is correct
8 Correct 1 ms 288 KB Output is correct
9 Correct 1 ms 204 KB Output is correct
10 Correct 1 ms 204 KB Output is correct
11 Correct 19 ms 340 KB Output is correct
12 Correct 15 ms 332 KB Output is correct
13 Correct 12 ms 332 KB Output is correct
14 Correct 19 ms 332 KB Output is correct
15 Correct 1 ms 204 KB Output is correct
16 Correct 1 ms 204 KB Output is correct
17 Correct 1 ms 204 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Runtime error 3 ms 844 KB Execution killed with signal 11
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
2 Runtime error 1 ms 588 KB Execution killed with signal 11
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 3 ms 204 KB Output is correct
2 Correct 9 ms 332 KB Output is correct
3 Correct 22 ms 332 KB Output is correct
4 Correct 22 ms 312 KB Output is correct
5 Correct 8 ms 292 KB Output is correct
6 Correct 1 ms 204 KB Output is correct
7 Correct 1 ms 296 KB Output is correct
8 Correct 1 ms 288 KB Output is correct
9 Correct 1 ms 204 KB Output is correct
10 Correct 1 ms 204 KB Output is correct
11 Correct 19 ms 340 KB Output is correct
12 Correct 15 ms 332 KB Output is correct
13 Correct 12 ms 332 KB Output is correct
14 Correct 19 ms 332 KB Output is correct
15 Correct 1 ms 204 KB Output is correct
16 Correct 1 ms 204 KB Output is correct
17 Correct 1 ms 204 KB Output is correct
18 Runtime error 2 ms 812 KB Execution killed with signal 11
19 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 3 ms 204 KB Output is correct
2 Correct 9 ms 332 KB Output is correct
3 Correct 22 ms 332 KB Output is correct
4 Correct 22 ms 312 KB Output is correct
5 Correct 8 ms 292 KB Output is correct
6 Correct 1 ms 204 KB Output is correct
7 Correct 1 ms 296 KB Output is correct
8 Correct 1 ms 288 KB Output is correct
9 Correct 1 ms 204 KB Output is correct
10 Correct 1 ms 204 KB Output is correct
11 Correct 19 ms 340 KB Output is correct
12 Correct 15 ms 332 KB Output is correct
13 Correct 12 ms 332 KB Output is correct
14 Correct 19 ms 332 KB Output is correct
15 Correct 1 ms 204 KB Output is correct
16 Correct 1 ms 204 KB Output is correct
17 Correct 1 ms 204 KB Output is correct
18 Runtime error 2 ms 812 KB Execution killed with signal 11
19 Halted 0 ms 0 KB -