답안 #200268

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
200268 2020-02-05T22:44:31 Z wjdqhdhfflavldkem12 곡선 자르기 (KOI17_cut) C++14
35 / 100
403 ms 69116 KB
#include <stdio.h>
#include <deque>
#include <list>
#include <stack>
#include <limits.h>
#include <algorithm>

using namespace std;

typedef pair<int, int> pi;
typedef struct{
	int x1;
	int x2;
}node;

int n, size, inX, outX;
list<pi> point;
node xx[100100];
list<int> peak;
stack<list<int> ::iterator> stk;
list<int> ::iterator iter;
list<pi> ::iterator iterp;

void pushPeak(list<int> ::iterator it, int a);

bool compare(node a, node b){
	return a.x1 < b.x1;
}

int main(){
	int i;
	
	int x, y, start;
	int minx = INT_MAX, miny = INT_MAX;

	scanf("%d", &n);
	//꼭짓점 좌표 디큐에 저장, 왼쪽 아래 시작 꼭짓점 찾기
	for (i = 0; i < n; i++){
		scanf("%d %d", &x, &y);
		point.push_back(pi(x, y));
		if (x <= minx&&y <= miny){
			start = i;
			minx = x; miny = y;
		}
	}
	//왼쪽 아래를 index 0으로 두게끔 변경
	for (i = 0; i < start; i++){
		pi temp = *point.begin();
		point.push_back(temp);
		point.pop_front();
	}

	//봉우리의 왼쪽, 오른쪽 기둥 x좌표 입력
	int temp;
	iterp = point.begin();
	for (i = 0; i < n; i++){
		while (i != n&& (*iterp).second < 0){
			i++;
			iterp++;
		}
		if (i == n)
			break;
		xx[size].x1 = (*iterp).first;
		while (i != n && (*iterp).second > 0){
			i++;
			iterp++;
		}
		if (i == n)
			break;
		xx[size].x2 = (*iterp).first;
		if (xx[size].x1>xx[size].x2){
			temp = xx[size].x1;
			xx[size].x1 = xx[size].x2;
			xx[size].x2 = temp;
		}
		size++;
		iterp++;
	}
	point.clear();

	//봉우리의 왼쪽기둥 x좌표 기준 오름차순 정렬
	sort(xx, xx+size, compare);

	//봉우리를 x좌표 기준으로 정렬, INT_MIN으로 봉우리를 구분한다.
	iter = peak.begin();
	for (i = 0; i < size; i++){
		if (stk.empty()){
			iter = peak.end();
			pushPeak(iter, i);
			iter--; iter--;
			stk.push(iter);
		}
		else{
			iter = stk.top();
			while (*iter < xx[i].x1){
				stk.pop();
				if (stk.empty()){
					iter = peak.end();
					break;
				}
				iter = stk.top();
			}
			pushPeak(iter, i);
			iter--; iter--;
			stk.push(iter);
		}
	}

	//peak 처음부터 끝까지 검사하며 answer 검사, 
	iter = peak.begin();
	list<int> ::iterator iter2;
	int num = 0; //미완성 봉우리 갯수
	while (iter != peak.end()){
		if (*iter == INT_MIN){
			num++;
		}
		else{
			num--;
			iter2 = iter;
			iter2--; iter2--;
			if (*iter2 == INT_MIN)
				inX++;
		}
		if (num == 0)
			outX++;
		iter++; iter++;
	}

	printf("%d %d\n", outX, inX);

	return 0;
}

void pushPeak(list<int> ::iterator it, int a){
	peak.insert(it, INT_MIN);
	peak.insert(it, xx[a].x1);
	peak.insert(it, xx[a].x2);
	peak.insert(it, INT_MIN);
	return;
}

Compilation message

cut.cpp: In function 'int main()':
cut.cpp:36:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d", &n);
  ~~~~~^~~~~~~~~~
cut.cpp:39:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%d %d", &x, &y);
   ~~~~~^~~~~~~~~~~~~~~~~
cut.cpp:47:16: warning: 'start' may be used uninitialized in this function [-Wmaybe-uninitialized]
  for (i = 0; i < start; i++){
              ~~^~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 256 KB Output is correct
2 Correct 5 ms 256 KB Output is correct
3 Correct 5 ms 376 KB Output is correct
4 Correct 5 ms 248 KB Output is correct
5 Correct 5 ms 376 KB Output is correct
6 Correct 5 ms 376 KB Output is correct
7 Correct 5 ms 248 KB Output is correct
8 Correct 5 ms 376 KB Output is correct
9 Correct 5 ms 376 KB Output is correct
10 Correct 5 ms 376 KB Output is correct
11 Correct 5 ms 376 KB Output is correct
12 Correct 5 ms 376 KB Output is correct
13 Correct 5 ms 380 KB Output is correct
14 Correct 5 ms 376 KB Output is correct
15 Correct 5 ms 376 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 256 KB Output is correct
2 Correct 5 ms 256 KB Output is correct
3 Correct 5 ms 376 KB Output is correct
4 Correct 5 ms 248 KB Output is correct
5 Correct 5 ms 376 KB Output is correct
6 Correct 5 ms 376 KB Output is correct
7 Correct 5 ms 248 KB Output is correct
8 Correct 5 ms 376 KB Output is correct
9 Correct 5 ms 376 KB Output is correct
10 Correct 5 ms 376 KB Output is correct
11 Correct 5 ms 376 KB Output is correct
12 Correct 5 ms 376 KB Output is correct
13 Correct 5 ms 380 KB Output is correct
14 Correct 5 ms 376 KB Output is correct
15 Correct 5 ms 376 KB Output is correct
16 Correct 5 ms 256 KB Output is correct
17 Correct 5 ms 376 KB Output is correct
18 Correct 6 ms 376 KB Output is correct
19 Correct 9 ms 760 KB Output is correct
20 Correct 9 ms 888 KB Output is correct
21 Correct 9 ms 888 KB Output is correct
22 Correct 10 ms 888 KB Output is correct
23 Correct 10 ms 888 KB Output is correct
24 Correct 10 ms 760 KB Output is correct
25 Correct 10 ms 760 KB Output is correct
26 Correct 10 ms 760 KB Output is correct
27 Correct 10 ms 760 KB Output is correct
28 Correct 9 ms 760 KB Output is correct
29 Correct 10 ms 888 KB Output is correct
30 Correct 9 ms 888 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 256 KB Output is correct
2 Correct 5 ms 256 KB Output is correct
3 Correct 5 ms 376 KB Output is correct
4 Correct 5 ms 248 KB Output is correct
5 Correct 5 ms 376 KB Output is correct
6 Correct 5 ms 376 KB Output is correct
7 Correct 5 ms 248 KB Output is correct
8 Correct 5 ms 376 KB Output is correct
9 Correct 5 ms 376 KB Output is correct
10 Correct 5 ms 376 KB Output is correct
11 Correct 5 ms 376 KB Output is correct
12 Correct 5 ms 376 KB Output is correct
13 Correct 5 ms 380 KB Output is correct
14 Correct 5 ms 376 KB Output is correct
15 Correct 5 ms 376 KB Output is correct
16 Correct 5 ms 256 KB Output is correct
17 Correct 5 ms 376 KB Output is correct
18 Correct 6 ms 376 KB Output is correct
19 Correct 9 ms 760 KB Output is correct
20 Correct 9 ms 888 KB Output is correct
21 Correct 9 ms 888 KB Output is correct
22 Correct 10 ms 888 KB Output is correct
23 Correct 10 ms 888 KB Output is correct
24 Correct 10 ms 760 KB Output is correct
25 Correct 10 ms 760 KB Output is correct
26 Correct 10 ms 760 KB Output is correct
27 Correct 10 ms 760 KB Output is correct
28 Correct 9 ms 760 KB Output is correct
29 Correct 10 ms 888 KB Output is correct
30 Correct 9 ms 888 KB Output is correct
31 Correct 104 ms 11092 KB Output is correct
32 Runtime error 403 ms 69116 KB Execution killed with signal 11 (could be triggered by violating memory limits)
33 Halted 0 ms 0 KB -