QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#596122 | #9221. Missing Boundaries | ucup-team4975# | WA | 33ms | 7820kb | C++14 | 2.8kb | 2024-09-28 15:10:45 | 2024-09-28 15:10:45 |
Judging History
answer
#define _CRT_SECURE_NO_WARNINGS
#include<algorithm>
#include<iostream>
#include<cstring>
#include<iomanip>
#include<vector>
#include<queue>
#include<set>
using namespace std;
const int N=200010;
int n,l,sum,cnt,vis[N],posvis[N];
struct Node{
int l,r,x,y,op;
//op==1 [?,r]
//op==2 [l,?]
//op==3 [l,r]
Node(){}
Node(int _l,int _r):l(_l),r(_r){}
inline bool operator<(const Node that)const{
return x<that.x;
}
}a[N];
signed main()
{
int T;
scanf("%d",&T);
while(T--)
{
bool valid=1;
sum=cnt=0;
scanf("%d%d",&n,&l);
int maxi=l,mini=0;
for(int i=1,x,y;i<=n;i++)
{
scanf("%d%d",&x,&y);
if(x==-1&&y==-1)
{
sum++;
continue;
}
a[++cnt]=Node(x,y);
if(a[cnt].l==-1)a[cnt].x=a[cnt].y=a[cnt].r,a[cnt].op=1;
else if(a[cnt].r==-1)a[cnt].x=a[cnt].y=a[cnt].l,a[cnt].op=2;
else a[cnt].x=a[cnt].l,a[cnt].y=a[cnt].r,a[cnt].op=3;
}
sort(a+1,a+1+cnt);
for(int i=1;i<=cnt;i++)
{
if(i>=2&&a[i].x<=a[i-1].y)
{
valid=0;
break;
}
maxi-=a[i].y-a[i].x+1;
}
if(!valid)
{
puts("NIE");
continue;
}
int lst=0; //lst是上一个被占据的位置
int pos=0; //pos==0 没有占据 pos=1 上次向右延申
for(int i=1;i<=cnt;i++)
{
if(a[i].op==1) //[?,r]
{
if(pos==0)
{
if(a[i].r-lst-1<1)
{
valid=0;
//cout<<"!1"<<endl;
break;
}
pos=0;
lst=a[i].r;
}
else
{
if(a[i].r-lst-1<2)
{
valid=0;
//cout<<"!2"<<endl;
break;
}
pos=0;
lst=a[i].r;
}
}
else if(a[i].op==2) //[l,?]
{
if(pos==0)
{
if(lst+1==a[i].l)
{
pos=1;
lst=a[i].l;
}
else
{
if(a[i].r-lst-1<2)
{
valid=0;
//cout<<"!3"<<endl;
break;
}
mini++;
pos=1;
lst=a[i].l;
}
}
else
{
if(a[i].r-lst-1<1)
{
valid=0;
//cout<<"!4"<<endl;
break;
}
pos=1;
lst=a[i].l;
}
}
else //[l,r]
{
if(pos==0)
{
if(lst+1==a[i].l)
{
pos=0;
lst=a[i].r;
}
else
{
if(a[i].l-lst-1<2)
{
valid=0;
//cout<<"!5"<<endl;
break;
}
mini++;
pos=0;
lst=a[i].r;
}
}
else
{
if(a[i].l-lst-1<1)
{
valid=0;
//cout<<"!6"<<endl;
break;
}
pos=0;
lst=a[i].r;
}
}
}
if(pos==0)
{
if(lst<l)
{
mini++;
}
}
else
{
if(l-lst<1)
//cout<<"!7"<<endl,
valid=0;
}
if(!valid)
{
puts("NIE");
continue;
}
//cout<<maxi<<" "<<mini<<endl;
if(sum>=mini&&sum<=maxi)
puts("TAK");
else puts("NIE");
}
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 3772kb
input:
3 4 51 1 -1 11 50 -1 -1 -1 10 3 2 -1 -1 -1 -1 -1 -1 2 3 1 2 2 3
output:
TAK NIE NIE
result:
ok 3 lines
Test #2:
score: -100
Wrong Answer
time: 33ms
memory: 7820kb
input:
1 200000 1000000000 490669427 -1 224278942 224287156 821104480 -1 861696576 861702036 807438935 807440055 574078002 574083717 465630141 -1 195378188 -1 -1 13500961 -1 977536179 92893115 -1 -1 661145418 -1 215804863 -1 685338515 544348999 -1 465532902 -1 130346949 -1 -1 526666304 635604584 635605404 ...
output:
NIE
result:
wrong answer 1st lines differ - expected: 'TAK', found: 'NIE'