답안 #200284

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
200284 2020-02-06T04:44:23 Z wjdqhdhfflavldkem12 곡선 자르기 (KOI17_cut) C++14
11 / 100
9 ms 632 KB
#include <stdio.h>
#include <vector>
#include <utility>
#include <algorithm>
#include <limits.h>

using namespace std;

#define LEFT 0
#define RIGHT 1
#define node pair<int, bool>

int n, inX, outX;
vector<node> LIST;

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

int main(){
	int i;

	scanf("%d", &n);

	int xtemp, ytemp, start;
	int minx = INT_MAX, miny = INT_MAX;
	vector<int> x, y;
	for (i = 0; i < n; i++){
		scanf("%d %d", &xtemp, &ytemp);
		x.push_back(xtemp);
		y.push_back(ytemp);
		if (xtemp <= minx&&ytemp <= miny){
			start = i;
			minx = xtemp; miny = ytemp;
		}
	}
	
	for (i = 0; i < start; i++){
		x.push_back(x[i]);
		y.push_back(y[i]);
	}

	int size = 0;
	for (i = start; i < n+start-1; i++){
		if (y[i]<0 && y[i + 1]>0){
			size++;
			i++;
			if (x[i]<x[i+1])
				LIST.push_back(node(x[i], LEFT));
			else
				LIST.push_back(node(x[i], RIGHT));
		}
		if (y[i]>0 && y[i + 1] < 0){
			size++;
			if (x[i] < x[i - 1])
				LIST.push_back(node(x[i], LEFT));
			else
				LIST.push_back(node(x[i], RIGHT));
		}
	}
	
	sort(LIST.begin(), LIST.end(), compare);
	
	int count = 0;
	for (i = 0; i < size; i++){
		if (LIST[i].second == LEFT){
			count++;
			if (count == 1)
				outX++;
		}
		else{
			count--;
			if (LIST[i - 1].second == LEFT)
				inX++;
		}
	}

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

	return 0;
}

Compilation message

cut.cpp: In function 'int main()':
cut.cpp:23:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d", &n);
  ~~~~~^~~~~~~~~~
cut.cpp:29:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%d %d", &xtemp, &ytemp);
   ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
cut.cpp:44:23: warning: 'start' may be used uninitialized in this function [-Wmaybe-uninitialized]
  for (i = start; i < n+start-1; 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 376 KB Output is correct
5 Correct 5 ms 376 KB Output is correct
6 Correct 5 ms 256 KB Output is correct
7 Correct 5 ms 256 KB Output is correct
8 Correct 5 ms 256 KB Output is correct
9 Correct 5 ms 256 KB Output is correct
10 Correct 5 ms 256 KB Output is correct
11 Correct 5 ms 256 KB Output is correct
12 Correct 5 ms 376 KB Output is correct
13 Correct 5 ms 256 KB Output is correct
14 Correct 5 ms 376 KB Output is correct
15 Correct 5 ms 248 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 376 KB Output is correct
5 Correct 5 ms 376 KB Output is correct
6 Correct 5 ms 256 KB Output is correct
7 Correct 5 ms 256 KB Output is correct
8 Correct 5 ms 256 KB Output is correct
9 Correct 5 ms 256 KB Output is correct
10 Correct 5 ms 256 KB Output is correct
11 Correct 5 ms 256 KB Output is correct
12 Correct 5 ms 376 KB Output is correct
13 Correct 5 ms 256 KB Output is correct
14 Correct 5 ms 376 KB Output is correct
15 Correct 5 ms 248 KB Output is correct
16 Correct 5 ms 376 KB Output is correct
17 Correct 5 ms 256 KB Output is correct
18 Correct 6 ms 376 KB Output is correct
19 Correct 8 ms 504 KB Output is correct
20 Correct 9 ms 632 KB Output is correct
21 Correct 9 ms 504 KB Output is correct
22 Correct 8 ms 504 KB Output is correct
23 Correct 9 ms 632 KB Output is correct
24 Correct 9 ms 632 KB Output is correct
25 Incorrect 8 ms 632 KB Output isn't correct
26 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 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 376 KB Output is correct
5 Correct 5 ms 376 KB Output is correct
6 Correct 5 ms 256 KB Output is correct
7 Correct 5 ms 256 KB Output is correct
8 Correct 5 ms 256 KB Output is correct
9 Correct 5 ms 256 KB Output is correct
10 Correct 5 ms 256 KB Output is correct
11 Correct 5 ms 256 KB Output is correct
12 Correct 5 ms 376 KB Output is correct
13 Correct 5 ms 256 KB Output is correct
14 Correct 5 ms 376 KB Output is correct
15 Correct 5 ms 248 KB Output is correct
16 Correct 5 ms 376 KB Output is correct
17 Correct 5 ms 256 KB Output is correct
18 Correct 6 ms 376 KB Output is correct
19 Correct 8 ms 504 KB Output is correct
20 Correct 9 ms 632 KB Output is correct
21 Correct 9 ms 504 KB Output is correct
22 Correct 8 ms 504 KB Output is correct
23 Correct 9 ms 632 KB Output is correct
24 Correct 9 ms 632 KB Output is correct
25 Incorrect 8 ms 632 KB Output isn't correct
26 Halted 0 ms 0 KB -