제출 #200284

#제출 시각아이디문제언어결과실행 시간메모리
200284wjdqhdhfflavldkem12곡선 자르기 (KOI17_cut)C++14
11 / 100
9 ms632 KiB
#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;
}

컴파일 시 표준 에러 (stderr) 메시지

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++){
                      ~^~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...