답안 #1054089

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1054089 2024-08-12T06:11:12 Z 김은성(#11056) 무지개나라 (APIO17_rainbow) C++14
12 / 100
39 ms 1928 KB
#include "rainbow.h"
#include <bits/stdc++.h>
using namespace std;
int dr[4] = {-1, 0, 1, 0}, dc[4] = {0, 1, 0, -1};
char dir[4] = {'N', 'E', 'S', 'W'};
bool ch[3][200009];
bool done[3][200009];
vector<int> s1, e1, s2, e2, s12, e12;
int n, m;
int r1, r2, c1, c2;
bool exist(int tr, int tc){
	return tr>=r1 && tr<=r2 && tc>=c1 && tc<=c2;
}
void dfs(int r, int c){
	done[r][c] = 1;
	for(int k=0; k<4; k++){
		int tr = r + dr[k];
		int tc = c + dc[k];
		if(exist(tr, tc) && !ch[tr][tc] && !done[tr][tc]){
			dfs(tr, tc);
		}
	}
}
void init(int R, int C, int sr, int sc, int M, char *S) {
	n = R;
	m = C;
	ch[sr][sc] = 1;
	for(int i=0; i<M; i++){
		int k;
		for(k=0; k<4; k++){
			if(S[i] == dir[k])
				break;
		}
		sr += dr[k];
		sc += dc[k];
		ch[sr][sc] = 1;
	}
	int i;
	for(i=1; i<=C; i++){
		if(!ch[1][i] && (i==1 || ch[1][i-1])){
			s1.push_back(i);
		}
		if(!ch[2][i] && (i==1 || ch[2][i-1])){
			s2.push_back(i);
		}
		if(!ch[1][i] && (i==C || ch[1][i+1])){
			e1.push_back(i);
		}
		if(!ch[2][i] && (i==C || ch[2][i+1])){
			e2.push_back(i);
		}
		if(!(ch[1][i] && ch[2][i]) && (i==1 || (ch[1][i-1] && ch[2][i-1]))){
			s12.push_back(i);
			//printf("s12: %d\n", i);
		}
		if(!(ch[1][i] && ch[2][i]) && (i==C || (ch[1][i+1] && ch[2][i+1]))){
			e12.push_back(i);
			//printf("e12: %d\n", i);
		}
	}
}
int colour(int ar, int ac, int br, int bc) {
	int i, j;
	if(ar==1 && br==1){
		//printf("here\n");
		int idx1 = lower_bound(e1.begin(), e1.end(), ac) - e1.begin();
		int idx2 = upper_bound(s1.begin(), s1.end(), bc) - s1.begin() - 1;
		return idx2 - idx1 + 1;
	}
	
	if(ar==2 && br==2){
		int idx1 = lower_bound(e2.begin(), e2.end(), ac) - e2.begin();
		int idx2 = upper_bound(s2.begin(), s2.end(), bc) - s2.begin() - 1;
		return idx2 - idx1 + 1;
	}
	
	if(ar==1 && br==2){
		int idx1 = lower_bound(e12.begin(), e12.end(), ac) - e12.begin();
		int idx2 = upper_bound(s12.begin(), s12.end(), bc) - s12.begin() - 1;
		return idx2 - idx1 + 1;
	}
}

Compilation message

rainbow.cpp: In function 'int colour(int, int, int, int)':
rainbow.cpp:63:6: warning: unused variable 'i' [-Wunused-variable]
   63 |  int i, j;
      |      ^
rainbow.cpp:63:9: warning: unused variable 'j' [-Wunused-variable]
   63 |  int i, j;
      |         ^
rainbow.cpp:82:1: warning: control reaches end of non-void function [-Wreturn-type]
   82 | }
      | ^
# 결과 실행 시간 메모리 Grader output
1 Runtime error 1 ms 344 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 26 ms 1212 KB Output is correct
4 Correct 29 ms 1400 KB Output is correct
5 Correct 31 ms 1620 KB Output is correct
6 Correct 30 ms 1500 KB Output is correct
7 Correct 39 ms 1928 KB Output is correct
8 Correct 26 ms 1116 KB Output is correct
9 Correct 29 ms 1364 KB Output is correct
10 Correct 32 ms 1620 KB Output is correct
11 Correct 31 ms 1368 KB Output is correct
12 Correct 24 ms 1112 KB Output is correct
13 Correct 26 ms 1368 KB Output is correct
14 Correct 25 ms 1624 KB Output is correct
15 Correct 25 ms 1420 KB Output is correct
16 Correct 26 ms 1112 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Runtime error 1 ms 856 KB Execution killed with signal 11
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 1 ms 344 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 1 ms 344 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -