Submission #200270

# Submission time Handle Problem Language Result Execution time Memory
200270 2020-02-05T23:20:10 Z wjdqhdhfflavldkem12 None (KOI17_cut) C++14
35 / 100
104 ms 13920 KB
#define Le 0
#define Ri 1
#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 검사, 
	bool lr[25000];
	iter = peak.begin();
	size = 0;
	while (iter != peak.end()){
		if (*iter == INT_MIN)
			lr[size] = Le;
		else
			lr[size] = Ri;
		size++;
		iter++; iter++;
	}
	int num = 0;
	for (int i = 0; i < size; i++){
		if (lr[i] == Le){
			num++;
			if (num == 1)
				outX++;
		}
		else{
			num--;
			if (lr[i - 1] == Le)
				inX++;
		}
	}

	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:38:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d", &n);
  ~~~~~^~~~~~~~~~
cut.cpp:41: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:49:16: warning: 'start' may be used uninitialized in this function [-Wmaybe-uninitialized]
  for (i = 0; i < start; i++){
              ~~^~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 5 ms 256 KB Output is correct
2 Correct 5 ms 376 KB Output is correct
3 Correct 5 ms 376 KB Output is correct
4 Correct 5 ms 376 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 376 KB Output is correct
8 Correct 5 ms 256 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 372 KB Output is correct
14 Correct 5 ms 376 KB Output is correct
15 Correct 5 ms 376 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 256 KB Output is correct
2 Correct 5 ms 376 KB Output is correct
3 Correct 5 ms 376 KB Output is correct
4 Correct 5 ms 376 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 376 KB Output is correct
8 Correct 5 ms 256 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 372 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 376 KB Output is correct
17 Correct 5 ms 376 KB Output is correct
18 Correct 6 ms 376 KB Output is correct
19 Correct 8 ms 632 KB Output is correct
20 Correct 9 ms 632 KB Output is correct
21 Correct 9 ms 632 KB Output is correct
22 Correct 11 ms 632 KB Output is correct
23 Correct 10 ms 632 KB Output is correct
24 Correct 9 ms 632 KB Output is correct
25 Correct 9 ms 632 KB Output is correct
26 Correct 10 ms 632 KB Output is correct
27 Correct 9 ms 632 KB Output is correct
28 Correct 9 ms 632 KB Output is correct
29 Correct 9 ms 632 KB Output is correct
30 Correct 10 ms 632 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 256 KB Output is correct
2 Correct 5 ms 376 KB Output is correct
3 Correct 5 ms 376 KB Output is correct
4 Correct 5 ms 376 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 376 KB Output is correct
8 Correct 5 ms 256 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 372 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 376 KB Output is correct
17 Correct 5 ms 376 KB Output is correct
18 Correct 6 ms 376 KB Output is correct
19 Correct 8 ms 632 KB Output is correct
20 Correct 9 ms 632 KB Output is correct
21 Correct 9 ms 632 KB Output is correct
22 Correct 11 ms 632 KB Output is correct
23 Correct 10 ms 632 KB Output is correct
24 Correct 9 ms 632 KB Output is correct
25 Correct 9 ms 632 KB Output is correct
26 Correct 10 ms 632 KB Output is correct
27 Correct 9 ms 632 KB Output is correct
28 Correct 9 ms 632 KB Output is correct
29 Correct 9 ms 632 KB Output is correct
30 Correct 10 ms 632 KB Output is correct
31 Runtime error 104 ms 13920 KB Execution killed with signal 11 (could be triggered by violating memory limits)
32 Halted 0 ms 0 KB -