답안 #902789

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
902789 2024-01-11T02:50:25 Z vjudge1 무지개나라 (APIO17_rainbow) C++11
11 / 100
3000 ms 1048576 KB
#include "rainbow.h"
#include<bits/stdc++.h>
using namespace std;
vector< vector<bool> >matriz;
void init(int R, int C, int sr, int sc, int M, char *S) {
    matriz = vector< vector<bool> > (R,vector<bool>(C,true));
    sr--;
    sc--;
    matriz[sr][sc]=0;
    for(int i=0;i<M;i++){///marcando el camino de la serpiente
        int dir=S[i];
        if(dir=='N')sr--;
        if(dir=='W')sc--;
        if(dir=='S')sr++;
        if(dir=='E')sc++;
        matriz[sr][sc]=0;
    }
}
int colour(int ar, int ac, int br, int bc) {
    ar--;
    ac--;
    br--;
    bc--;
    vector< vector<bool> >visitados(matriz.size(),vector<bool> (matriz[0].size(),false));
    int cont=0;
    for(int i=ar;i<=br;i++){
        for(int j=ac;j<=bc;j++){
            if(matriz[i][j] && !visitados[i][j]){///si no esta pintado y podemos ir por ahí
                visitados[i][j]=1;///lo pintamos
                cont++;///nuevo color
                queue< pair<int,int> >q;///cola donde almacenaremos los caminos
                q.push(make_pair(i,j));///comenzaremos nuestro camino
                while(!q.empty()){
                    int px=q.front().first,py=q.front().second,px1=px-1,py1=py,px2=px,py2=py-1,px3=px+1,py3=py,px4=px,py4=py+1;///designando nuevas direcciones a N,W,S,E
                    q.pop();
                    if(px1>=ar && px1<=br && py1>=ac && py1<=bc){///si es territorio dentro de la zona
                        if(matriz[px1][py1] && !visitados[px1][py1]){///si no esta pintado y podemos ir por ahí
                            visitados[px1][py1]=1;///lo pintamos
                            q.push(make_pair(px1,py1));///nuevo camino
                        }
                    }
                    if(px2>=ar && px2<=br && py2>=ac && py2<=bc){
                          if(matriz[px2][py2] && !visitados[px2][py2]){
                            visitados[px2][py2]=1;
                            q.push(make_pair(px2,py2));
                        }
                    }
                    if(px3>=ar && px3<=br && py3>=ac && py3<=bc){
                       if(matriz[px3][py3] && !visitados[px3][py3]){
                            visitados[px3][py3]=1;
                            q.push(make_pair(px3,py3));
                        }
                    }
                    if(px4>=ar && px4<=br && py4>=ac && py4<=bc){
                         if(matriz[px4][py4] && !visitados[px4][py4]){
                            visitados[px4][py4]=1;
                            q.push(make_pair(px4,py4));
                        }
                    }
                }
            }
        }
    }
    return cont;
}
/*int main(){
    int R,C,M,Q,sr,sc,ar,ac,br,bc;
    string S;
    cin>>R>>C>>M>>Q;
    cin>>sr>>sc;
    cin>>S;
    init(R,C,sr,sc,M,S);
    for(int i=0;i<Q;i++){
        cin>>ar>>ac>>br>>bc;
        int ans=colour(ar,ac,br,bc);
        cout<<ans<<"\n";
    }
    return 0;
}*/
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 344 KB Output is correct
2 Correct 13 ms 344 KB Output is correct
3 Correct 17 ms 480 KB Output is correct
4 Correct 19 ms 348 KB Output is correct
5 Correct 10 ms 488 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
7 Correct 0 ms 344 KB Output is correct
8 Correct 1 ms 420 KB Output is correct
9 Correct 1 ms 348 KB Output is correct
10 Correct 1 ms 348 KB Output is correct
11 Correct 15 ms 352 KB Output is correct
12 Correct 14 ms 348 KB Output is correct
13 Correct 12 ms 344 KB Output is correct
14 Correct 14 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 0 ms 348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Execution timed out 3016 ms 1012 KB Time limit exceeded
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Runtime error 533 ms 1048576 KB Execution killed with signal 9
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 344 KB Output is correct
2 Correct 13 ms 344 KB Output is correct
3 Correct 17 ms 480 KB Output is correct
4 Correct 19 ms 348 KB Output is correct
5 Correct 10 ms 488 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
7 Correct 0 ms 344 KB Output is correct
8 Correct 1 ms 420 KB Output is correct
9 Correct 1 ms 348 KB Output is correct
10 Correct 1 ms 348 KB Output is correct
11 Correct 15 ms 352 KB Output is correct
12 Correct 14 ms 348 KB Output is correct
13 Correct 12 ms 344 KB Output is correct
14 Correct 14 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 0 ms 348 KB Output is correct
18 Execution timed out 3086 ms 1244 KB Time limit exceeded
19 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 344 KB Output is correct
2 Correct 13 ms 344 KB Output is correct
3 Correct 17 ms 480 KB Output is correct
4 Correct 19 ms 348 KB Output is correct
5 Correct 10 ms 488 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
7 Correct 0 ms 344 KB Output is correct
8 Correct 1 ms 420 KB Output is correct
9 Correct 1 ms 348 KB Output is correct
10 Correct 1 ms 348 KB Output is correct
11 Correct 15 ms 352 KB Output is correct
12 Correct 14 ms 348 KB Output is correct
13 Correct 12 ms 344 KB Output is correct
14 Correct 14 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 0 ms 348 KB Output is correct
18 Execution timed out 3086 ms 1244 KB Time limit exceeded
19 Halted 0 ms 0 KB -