답안 #67131

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
67131 2018-08-13T11:13:52 Z ege_eksi DEL13 (info1cup18_del13) C++14
6 / 100
25 ms 1628 KB
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<climits>
#include<algorithm>
#include<queue>
#include<vector>
#include<list>

using namespace std;

struct node
{
	int start , end;
	int dist;
};

class mycomparison
{
public:

  bool operator() (const  node a, const node b) const
  {
  		if(a.dist > b.dist)
  		{
  			return 0;
		  }
		else if(a.dist < b.dist)
		{
			return 1;
		}
		else if(a.start < b.start)
		{
			return 0;
		}
		else
		{
			return 1;
		}
	 }
};


priority_queue< node , vector<node> , mycomparison > pq;

int n , q;
int a[100001];

list<int> moves;

void func()
{
	while(!pq.empty())
	{
		pq.pop();
	}
	
	moves.clear();
	
	node x;
	
	x.start = 0;
	x.end = a[0];
	x.dist = x.end - x.start - 1;
	
	pq.push(x);
	
	for(int i = 1 ; i < q ; i++)
	{
		x.start = a[i-1];
		x.end = a[i];
		x.dist = x.end - x.start - 1;
		
		pq.push(x);
	}
	
	x.start = a[q-1];
	x.end = n+1;
	x.dist = x.end - x.start - 1;
	
	pq.push(x);
	
	node y;
	
	while(!pq.empty())
	{
		x = pq.top();
		pq.pop();
		
		if(x.dist == 0)
		{
			break;
		}
		
		else if(x.dist > 2)
		{
			x.dist -= 2;
			pq.push(x);
		}
		else if(x.dist == 1)
		{
			if(!pq.empty() && pq.top().dist == 1)
			{
				y = pq.top();
				pq.pop();
				
				x.dist = 0;
				y.dist = 0;
				
				pq.push(x);
				pq.push(y);
			}
			else
			{
				printf("-1 ");
				return;
			}
		}
		else
		{
			if(!pq.empty() && pq.top().dist == 2)
			{
				y = pq.top();
				pq.pop();
				
				x.dist = 1;
				y.dist = 1;
				
				pq.push(x);
				pq.push(y);
			}
			else
			{
				printf("-1 ");
				return;
			}
		}
	}
	
	printf("0\n");
}



int main()
{
	int t;
	scanf("%d" , &t);
	
	
	while(t--)
	{
		scanf("%d %d",&n,&q);
		
		for(int i = 0 ; i < q ; i++)
		{
			scanf("%d" , &a[i]);
		}
		
		func();
	}
	
	return 0;
}

Compilation message

del13.cpp: In function 'int main()':
del13.cpp:148:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d" , &t);
  ~~~~~^~~~~~~~~~~
del13.cpp:153:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%d %d",&n,&q);
   ~~~~~^~~~~~~~~~~~~~~
del13.cpp:157:9: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
    scanf("%d" , &a[i]);
    ~~~~~^~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Incorrect 3 ms 248 KB Output isn't correct
2 Incorrect 3 ms 356 KB Output isn't correct
# 결과 실행 시간 메모리 Grader output
1 Incorrect 3 ms 248 KB Output isn't correct
2 Incorrect 3 ms 356 KB Output isn't correct
3 Incorrect 7 ms 560 KB Output isn't correct
4 Incorrect 11 ms 560 KB Output isn't correct
# 결과 실행 시간 메모리 Grader output
1 Partially correct 10 ms 560 KB Output is partially correct
2 Partially correct 13 ms 564 KB Output is partially correct
# 결과 실행 시간 메모리 Grader output
1 Incorrect 3 ms 248 KB Output isn't correct
2 Incorrect 3 ms 356 KB Output isn't correct
3 Incorrect 7 ms 560 KB Output isn't correct
4 Incorrect 11 ms 560 KB Output isn't correct
5 Incorrect 3 ms 564 KB Output isn't correct
6 Incorrect 3 ms 564 KB Output isn't correct
7 Incorrect 3 ms 564 KB Output isn't correct
# 결과 실행 시간 메모리 Grader output
1 Incorrect 3 ms 248 KB Output isn't correct
2 Incorrect 3 ms 356 KB Output isn't correct
3 Incorrect 7 ms 560 KB Output isn't correct
4 Incorrect 11 ms 560 KB Output isn't correct
5 Incorrect 3 ms 564 KB Output isn't correct
6 Incorrect 3 ms 564 KB Output isn't correct
7 Incorrect 3 ms 564 KB Output isn't correct
8 Incorrect 20 ms 736 KB Output isn't correct
9 Incorrect 24 ms 1152 KB Output isn't correct
10 Incorrect 25 ms 1188 KB Output isn't correct
11 Incorrect 23 ms 1628 KB Output isn't correct