Submission #57337

# Submission time Handle Problem Language Result Execution time Memory
57337 2018-07-14T14:58:30 Z IvanC Land of the Rainbow Gold (APIO17_rainbow) C++17
11 / 100
29 ms 1028 KB
#include "rainbow.h"
#include <bits/stdc++.h>
using namespace std;

const int MAXN = 60;
const int dx[4] = {1,-1,0,0};
const int dy[4] = {0,0,1,-1};

int matriz[MAXN][MAXN],tamx,tamy;
int processado[MAXN][MAXN];
int lo_x,lo_y,hi_x,hi_y;

inline int valido(int x,int y){
	return x >= lo_x && y >= lo_y && x <= hi_x && y <= hi_y && matriz[x][y] != 1; 
}

void dfs(int x,int y){
	if(processado[x][y]) return;
	//printf("DFS %d %d\n",x,y);
	processado[x][y] = 1;
	for(int i = 0;i<4;i++){
		int nx = x + dx[i];
		int ny = y + dy[i];
		if(valido(nx,ny)) dfs(nx,ny);
	}
}

void init(int R, int C, int sr, int sc, int M, char *S) {
	tamx = R;tamy= C;
	matriz[sr][sc] = 1;
	for(int vez = 0;vez<M;vez++){
		if(S[vez] == 'N'){
			//printf("N\n");
			sr--;
		}
		else if(S[vez] == 'W'){
			//printf("W\n");
			sc--;
		}
		else if(S[vez] == 'S'){
			//printf("S\n");
			sr++;
		}
		else{
			//printf("E\n");
			sc++;
		}
		//printf("%d %d\n",sr,sc);
		matriz[sr][sc] = 1;
	}
	//for(int i = 1;i<=tamx;i++){
	//	for(int j = 1;j<=tamy;j++){
	//		printf("%d",matriz[i][j]);
	//	}
	//	printf("\n");
	//}
}

int colour(int ar, int ac, int br, int bc) {
    if(tamx <= 50 && tamy <= 50){
		memset(processado,0,sizeof(processado));
    		int total = 0;
    		lo_x = ar;lo_y = ac;
    		hi_x = br;hi_y = bc;
    		for(int i = ar;i<=br;i++){
    			for(int j = ac;j <= bc;j++){
    				if(matriz[i][j] == 1 || processado[i][j]) continue;
    				//printf("Componente nova\n");
    				dfs(i,j);
    				total++;
    			}
    		}
    		return total;
	}
	else return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 4 ms 376 KB Output is correct
2 Correct 10 ms 376 KB Output is correct
3 Correct 29 ms 560 KB Output is correct
4 Correct 24 ms 564 KB Output is correct
5 Correct 14 ms 628 KB Output is correct
6 Correct 3 ms 628 KB Output is correct
7 Correct 2 ms 628 KB Output is correct
8 Correct 2 ms 628 KB Output is correct
9 Correct 2 ms 628 KB Output is correct
10 Correct 2 ms 628 KB Output is correct
11 Correct 29 ms 628 KB Output is correct
12 Correct 23 ms 628 KB Output is correct
13 Correct 16 ms 628 KB Output is correct
14 Correct 6 ms 656 KB Output is correct
15 Correct 2 ms 656 KB Output is correct
16 Correct 2 ms 676 KB Output is correct
17 Correct 3 ms 676 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 676 KB Output is correct
2 Correct 3 ms 676 KB Output is correct
3 Runtime error 4 ms 932 KB Execution killed with signal 11 (could be triggered by violating memory limits)
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 656 KB Output is correct
2 Runtime error 4 ms 980 KB Execution killed with signal 11 (could be triggered by violating memory limits)
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 4 ms 376 KB Output is correct
2 Correct 10 ms 376 KB Output is correct
3 Correct 29 ms 560 KB Output is correct
4 Correct 24 ms 564 KB Output is correct
5 Correct 14 ms 628 KB Output is correct
6 Correct 3 ms 628 KB Output is correct
7 Correct 2 ms 628 KB Output is correct
8 Correct 2 ms 628 KB Output is correct
9 Correct 2 ms 628 KB Output is correct
10 Correct 2 ms 628 KB Output is correct
11 Correct 29 ms 628 KB Output is correct
12 Correct 23 ms 628 KB Output is correct
13 Correct 16 ms 628 KB Output is correct
14 Correct 6 ms 656 KB Output is correct
15 Correct 2 ms 656 KB Output is correct
16 Correct 2 ms 676 KB Output is correct
17 Correct 3 ms 676 KB Output is correct
18 Runtime error 4 ms 1028 KB Execution killed with signal 11 (could be triggered by violating memory limits)
19 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 4 ms 376 KB Output is correct
2 Correct 10 ms 376 KB Output is correct
3 Correct 29 ms 560 KB Output is correct
4 Correct 24 ms 564 KB Output is correct
5 Correct 14 ms 628 KB Output is correct
6 Correct 3 ms 628 KB Output is correct
7 Correct 2 ms 628 KB Output is correct
8 Correct 2 ms 628 KB Output is correct
9 Correct 2 ms 628 KB Output is correct
10 Correct 2 ms 628 KB Output is correct
11 Correct 29 ms 628 KB Output is correct
12 Correct 23 ms 628 KB Output is correct
13 Correct 16 ms 628 KB Output is correct
14 Correct 6 ms 656 KB Output is correct
15 Correct 2 ms 656 KB Output is correct
16 Correct 2 ms 676 KB Output is correct
17 Correct 3 ms 676 KB Output is correct
18 Runtime error 4 ms 1028 KB Execution killed with signal 11 (could be triggered by violating memory limits)
19 Halted 0 ms 0 KB -