답안 #1054223

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1054223 2024-08-12T07:45:31 Z 김은성(#11056) 무지개나라 (APIO17_rainbow) C++14
0 / 100
32 ms 43260 KB
#include "rainbow.h"
#include <bits/stdc++.h>
using namespace std;
int n, m, dr[4] = {-1, 0, 1, 0}, dc[4] = {0, 1, 0, -1};
char dir[4] = {'N', 'E', 'S', 'W'};
vector<int> board[200009];
vector<tuple<int, int, int> > ran[200009];
void init(int R, int C, int sr, int sc, int M, char *S) {
	n = R;
	m = C;
	board[sr].push_back(sc);
	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];
		board[sr].push_back(sc);
	}
	for(int i=1; i<=n; i++){
		board[i].push_back(0), board[i].push_back(m+1);
		sort(board[i].begin(), board[i].end());
		board[i].erase(unique(board[i].begin(), board[i].end()), board[i].end());
	}
}
bool overlap(tuple<int, int, int> u, tuple<int, int, int> v){
	auto [s0, s1, e1] = u;
	auto [e0, s2, e2] = v;
	return (s2 <= e1 && s1 <= e2);
}
int colour2(int ar, int ac, int br, int bc) {
	if(ar>br)
		return 0;
	int i, j, k;
	for(i=ar; i<=br; i++){
		//printf("i=%d board.size=%d\n", i,board[i].size());
		for(j=0; j+1<board[i].size(); j++){
			//printf("i=%d j=%d\n", i, j);
			if(board[i][j+1] - board[i][j] >= 2 && max(board[i][j]+1, ac) <= min(board[i][j+1]-1, bc))
				ran[i].push_back(make_tuple(-1, max(board[i][j]+1, ac), min(board[i][j+1]-1, bc)));
		}
	}
	int ans = 0;
	for(j=0; j<ran[ar].size(); j++)
		get<0>(ran[ar][j]) = j;
	for(j=ar+1; j<=br; j++){
		//printf("j=%d\n", j);
		//printf("ran[j-1]=%d j=%d\n", ran[j-1].size(), ran[j].size());
		vector<bool> ch(get<0>(ran[j-1].back()) + 1);
		vector<int> inv(get<0>(ran[j-1].back()) + 1);
		for(int k=0; k<inv.size(); k++)
			inv[k ]= -1;
		int cnt = 0, p1 = 0, p2 = 0;
		while(p1 < ran[j-1].size() && p2 < ran[j].size()){
			//printf("p1=%d p2=%d\n", p1, p2);
			if(overlap(ran[j-1][p1], ran[j][p2])){
				ch[get<0>(ran[j-1][p1])] = 1;
				if(p2 > 0 && inv[get<0>(ran[j-1][p1])] != -1)
					get<0>(ran[j][p2]) = inv[get<0>(ran[j-1][p1])];
				else if(get<0>(ran[j][p2]) == -1){
					get<0>(ran[j][p2]) = (p2==0 ? -1 : get<0>(ran[j][p2-1])) + 1;
					inv[get<0>(ran[j-1][p1])] = get<0>(ran[j][p2]);
				}
			}
			else if(get<0>(ran[j][p2]) == -1)
				get<0>(ran[j][p2]) = (p2==0 ? -1 : get<0>(ran[j][p2-1])) + 1;
			if(p1+1 == ran[j-1].size())
				p2++;
			else if(p2+1 == ran[j].size())
				p1++;
			else if(get<2>(ran[j-1][p1]) < get<2>(ran[j][p2]))
				p1++;
			else
				p2++;
		}
		for(i=0; i<ch.size(); i++){
			if(!ch[i])
				ans++;
		}
	}
	ans += get<0>(ran[br].back()) + 1;
	return ans;
}
int colour(int ar, int ac, int br, int bc) {
	int ans = 0, i, j;
	int last = ar-1;
	for(i=ar; i<=br; i++){
		if(upper_bound(board[i].begin(), board[i].end(), bc) - lower_bound(board[i].begin(), board[i].end(), ac) == bc-ac+1){
			//printf("i=%d\n", i);
			ans += colour2(last+1, ac, i-1, bc);
			last = i;
		}
	}
	ans += colour2(last+1, ac, br, bc);
	return ans;
}

Compilation message

rainbow.cpp: In function 'bool overlap(std::tuple<int, int, int>, std::tuple<int, int, int>)':
rainbow.cpp:29:7: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
   29 |  auto [s0, s1, e1] = u;
      |       ^
rainbow.cpp:30:7: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
   30 |  auto [e0, s2, e2] = v;
      |       ^
rainbow.cpp: In function 'int colour2(int, int, int, int)':
rainbow.cpp:39:15: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   39 |   for(j=0; j+1<board[i].size(); j++){
      |            ~~~^~~~~~~~~~~~~~~~
rainbow.cpp:46:12: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::tuple<int, int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   46 |  for(j=0; j<ran[ar].size(); j++)
      |           ~^~~~~~~~~~~~~~~
rainbow.cpp:53:17: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   53 |   for(int k=0; k<inv.size(); k++)
      |                ~^~~~~~~~~~~
rainbow.cpp:56:12: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::tuple<int, int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   56 |   while(p1 < ran[j-1].size() && p2 < ran[j].size()){
      |         ~~~^~~~~~~~~~~~~~~~~
rainbow.cpp:56:36: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::tuple<int, int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   56 |   while(p1 < ran[j-1].size() && p2 < ran[j].size()){
      |                                 ~~~^~~~~~~~~~~~~~~
rainbow.cpp:69:12: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::tuple<int, int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   69 |    if(p1+1 == ran[j-1].size())
      |       ~~~~~^~~~~~~~~~~~~~~~~~
rainbow.cpp:71:17: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::tuple<int, int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   71 |    else if(p2+1 == ran[j].size())
      |            ~~~~~^~~~~~~~~~~~~~~~
rainbow.cpp:78:13: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<bool>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   78 |   for(i=0; i<ch.size(); i++){
      |            ~^~~~~~~~~~
rainbow.cpp:55:7: warning: unused variable 'cnt' [-Wunused-variable]
   55 |   int cnt = 0, p1 = 0, p2 = 0;
      |       ^~~
rainbow.cpp:36:12: warning: unused variable 'k' [-Wunused-variable]
   36 |  int i, j, k;
      |            ^
rainbow.cpp: In function 'int colour(int, int, int, int)':
rainbow.cpp:87:18: warning: unused variable 'j' [-Wunused-variable]
   87 |  int ans = 0, i, j;
      |                  ^
# 결과 실행 시간 메모리 Grader output
1 Incorrect 27 ms 10076 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 2 ms 9816 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 9816 KB Output is correct
2 Correct 19 ms 19728 KB Output is correct
3 Correct 17 ms 17720 KB Output is correct
4 Correct 17 ms 17672 KB Output is correct
5 Correct 17 ms 17880 KB Output is correct
6 Correct 27 ms 21072 KB Output is correct
7 Runtime error 32 ms 43260 KB Execution killed with signal 11
8 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 27 ms 10076 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 27 ms 10076 KB Output isn't correct
2 Halted 0 ms 0 KB -