Submission #106987

# Submission time Handle Problem Language Result Execution time Memory
106987 2019-04-21T11:46:22 Z piri007 None (KOI17_cut) C++14
0 / 100
3 ms 384 KB
#include <bits/stdc++.h>

using namespace std;

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

int buho(int t) //양수면 ( 리턴
{
	if (t > 0) return 0;
	else return 1;
}

int main()
{
	int n, x, y = 0, num[] = {0, 0};
	scanf("%d", &n);
	for (int i = 0; i < n; i++)
	{
		int a, b;
		scanf("%d %d", &a, &b);
		if (y && b*y < 0)
		{
			/*q.emplace(-a, buho(b)),*/ q.emplace(-a, num[0]);

			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())
	{
		//printf("왜 안됨?\n");
		//int garo = q.top().second;  //0이 (, 1이 )
		int mat = q.top().second;  //0부터 시작
		q.pop();
		//printf("mat : %d, size : %d\n", mat, s.size());

		//printf("왜 안됨?\n");
		if (s.empty() || s.top() != mat) s.push(mat);
		else if (!s.empty()) s.pop();     //갇힘? 풀림?

		//printf("왜 안됨?\n");
		if (s.empty()) res1++;            //이 단계에서 풀렸으면 가장 밖
		if (mat == before) res2++;       //()모양일때 가장 안
		//printf("왜 안됨?\n");
		before = mat;
	}
	printf("%d %d", res1, res2);
}

Compilation message

cut.cpp: In function 'int main()':
cut.cpp:17:9: warning: variable 'x' set but not used [-Wunused-but-set-variable]
  int n, x, y = 0, num[] = {0, 0};
         ^
cut.cpp:18:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d", &n);
  ~~~~~^~~~~~~~~~
cut.cpp:22:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%d %d", &a, &b);
   ~~~~~^~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 3 ms 384 KB Output is correct
2 Correct 3 ms 256 KB Output is correct
3 Incorrect 3 ms 384 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 3 ms 384 KB Output is correct
2 Correct 3 ms 256 KB Output is correct
3 Incorrect 3 ms 384 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 3 ms 384 KB Output is correct
2 Correct 3 ms 256 KB Output is correct
3 Incorrect 3 ms 384 KB Output isn't correct
4 Halted 0 ms 0 KB -