QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#600104 | #9221. Missing Boundaries | leafmaple# | WA | 46ms | 5140kb | C++20 | 2.1kb | 2024-09-29 14:43:31 | 2024-09-29 14:43:31 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
#define ll long long
bool cmp(pair<int,int> x,pair<int,int> y)
{
if(x.first*x.second < 0 && y.first*y.second < 0 )
{
return abs(x.first*x.second) < abs(y.first * y.second );
}
else if(x.first*x.second < 0 )
return abs(x.first*x.second) < y.first;
else if(y.first*y.second < 0)
return x.first < abs(y.first * y.second );
else
return x.first < y.first;
}
void solve()
{
int n,L;
cin>>n>>L;
vector<pair<int,int> > v;
int nume = 0 ;
// 1:-> 2:<- 如果固定区间: 3:-> 4:<-
for(int i=0;i<n;i++)
{
int l,r;
cin>>l>>r;
if(l == -1 && r == -1)
nume ++;
else
v.push_back({l,r});
}
sort(v.begin(),v.end(),cmp);
int hs = 0 ;
int ls = 0;
int tag = 0 ; // 0 <- 1->
for(auto [l,r]:v)
{
//cout<<l<<' '<<r<<endl;
if((l == -1 && r <= ls) || (l == -1 && r <= ls) || (l != -1 && r != -1 && r <= ls ) )
{
cout<<"NIE"<<endl;
return ;
}
auto check=[&]()
{
if(nume)
{
nume -- ;
hs += l-2 - ls;
ls = l - 1;
return false ;
}
return true ;
};
if(l == -1)
{
hs += r - ls - 1;
ls = r;
tag = 0 ;
}
else if(r == -1)
{
//cout<<1<<endl;
if(ls != l-1 && tag == 0)
{
if(check())
{
cout<<"NIE"<<endl;
return ;
}
}
hs += l-ls-1;
ls = l;
tag = 1;
}
else
{
if(ls!= l-1 && tag == 0)
{
if(check())
{
cout<<"NIE"<<endl;
return ;
}
}
hs += l-ls-1;
ls = r;
tag = 0;
}
}
//cout<<nume<<' '<<hs<<endl;
if(tag == 1)
{
hs += L - ls;
ls = L;
tag = 0;
}
if(ls != L )
{
if(!nume)
{
cout<<"NIE"<<endl;
return ;
}
else
{
hs += L - ls;
ls = L;
}
}
//cout<<nume<<' '<<hs<<endl;
if(hs < nume)
{
cout<<"NIE"<<endl;
return ;
}
cout<<"TAK"<<endl;
}
signed main (){
std::ios::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
int t;
cin>>t;
while(t--)
solve();
}
详细
Test #1:
score: 100
Accepted
time: 0ms
memory: 3528kb
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: 46ms
memory: 5140kb
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'