# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
67131 | ege_eksi | DEL13 (info1cup18_del13) | C++14 | 25 ms | 1628 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#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 (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |