제출 #107000

#제출 시각아이디문제언어결과실행 시간메모리
107000piri007곡선 자르기 (KOI17_cut)C++14
0 / 100
4 ms400 KiB
#include <bits/stdc++.h>

using namespace std;

stack <int> s; //작동시 현재 갇혀있는가 안 갇혀있는가
priority_queue<pair<int, int>> q;//짝궁정하기

int main()
{
	int ban, ban2 = 0; //처음 y가 양수일 때의 반례를 해결해보자
	int fx, fy;
	int n, x, y = 0, num[] = {0, 0};
	scanf("%d", &n);
	for (int i = 0; i < n; i++)
	{
	//	printf("%d", i);
		int a, b;

		if (ban2 && i + 1 == n) a = fx, b = fy;
		else
			scanf("%d %d", &a, &b);

		if (!y && b > 0)
			num[1] = 1, ban2 = 1, fx = a, fy = b, n++;

		if (y && b*y < 0)
		{
			q.emplace(-a, num[0]);
			ban = -a;

			if (!num[1]) num[1]++;
			else num[0]++, num[1] = 0;
		}
		x = a, y = b;
	}

	int res1 = 0, res2 = 0, before = -1; 

	while (!q.empty())
	{
		int mat = q.top().second;  //0부터 시작
		if (ban2 && q.top().first == ban) mat = 0;
		q.pop();

	//	printf("mate : %d, size : %d\n", mat, s.size());
		if (s.empty() || s.top() != mat) s.push(mat);
		else if (!s.empty()) s.pop();     //갇힘? 풀림?

		if (s.empty()) res1++;            //이 단계에서 풀렸으면 가장 밖
		if (mat == before) res2++;       //()모양일때 가장 안

		before = mat;
	}
	printf("%d %d", res1, res2);
}

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

cut.cpp: In function 'int main()':
cut.cpp:12:9: warning: variable 'x' set but not used [-Wunused-but-set-variable]
  int n, x, y = 0, num[] = {0, 0};
         ^
cut.cpp:13:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d", &n);
  ~~~~~^~~~~~~~~~
cut.cpp:21:9: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
    scanf("%d %d", &a, &b);
    ~~~~~^~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...