QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#687455#9221. Missing Boundaries_Veritas#WA 105ms22388kbC++142.6kb2024-10-29 19:08:062024-10-29 19:08:07

Judging History

你现在查看的是最新测评结果

  • [2024-10-29 19:08:07]
  • 评测
  • 测评结果:WA
  • 用时:105ms
  • 内存:22388kb
  • [2024-10-29 19:08:06]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
#define int long long
int read() {
  int x=0,w=1; char ch=0;
  while(ch<'0'||ch>'9'){ if(ch=='-') w=-1; ch=getchar();}
  while(ch>='0'&&ch<='9'){ x=x*10+(ch-'0'); ch=getchar();}
  return x*w;
}
#define LEFT false
#define RIGHT true
struct HF{
  int pos;
  bool face;
  bool operator<(const HF &b) const {
    return pos<b.pos;
  } 
};
struct Itv{
  int l,r;
  bool operator<(const Itv &b) const{
    if(l==b.l) return r<b.r;
    return l<b.l;
  }
};
pair<int,int> solve(Itv U,vector<HF> v){
  int up = (U.r-U.l+1)-(v.size()), down = 0;
  if(v.size()==0) return make_pair(U.r-U.l+1,1);
  int n = v.size();
  if(v[0].face==LEFT&&v[0].pos!=U.l) ++down;
  if(v[n-1].face==RIGHT&&v[n-1].pos!=U.r) ++down;
  for(int i=1;i<n;++i){
    if(v[i-1].face==RIGHT&&v[i].face==LEFT&&v[i-1].pos+1==v[i].pos)
      ++down;
  }
  return make_pair(up,down);
}
bool work(){
  int n=read();
  int L=read();
  int any_cnt = 0;
  vector<HF> hf;
  vector<Itv> itv,emp;
  map<int,int> numcnt;
  while(n--) {
    int x=read(),y=read();
    if(x!=-1) numcnt[x]++;
    if(y!=-1) numcnt[y]++;
    if(x==-1){
      if(y==-1) ++any_cnt;
      else hf.push_back(HF{y,RIGHT});
    }
    else{
      if(y==-1) hf.push_back(HF{x,LEFT});
      else itv.push_back(Itv{x,y});
    }
  }
  for(auto& x:numcnt) if(x.second>1) return false;
  sort(hf.begin(),hf.end());
  sort(itv.begin(),itv.end());
  int n_itv = itv.size();
  for(int i=1;i<n_itv;++i){
    if(itv[i-1].r>=itv[i].l) return false;
  }
  int p_itv = 0;
  int n_hf = hf.size();
  for(int i=0;i<n_hf;++i){
    auto x = hf[i];
    while(p_itv<n_itv&&itv[p_itv].r<x.pos) ++p_itv;
    if(p_itv<n_itv&&itv[p_itv].l<=x.pos) return false;
  }
  if(itv.size()==0) emp.push_back(Itv{1,L});
  else{
    if(itv[0].l!=1) emp.push_back(Itv{1,itv[0].l-1});
    for(int i=1;i<n_itv;++i){
      if(itv[i-1].r+1==itv[i].l) continue;
      emp.push_back(Itv{itv[i-1].r+1,itv[i].l-1});
    }
    if(itv[n_itv-1].r!=L) emp.push_back(Itv{itv[n_itv-1].r+1,L});
  }
  if(emp.size()==0) return any_cnt==0;
  int up = 0, down = 0;
  int hf_flag = 0;
  for(auto &space : emp){
    vector<HF> loc;
    while(hf_flag<n_hf&&hf[hf_flag].pos<space.l) hf_flag++;
    int end_flag;
    for(end_flag=hf_flag;end_flag<n_hf&&hf[end_flag].pos<=space.r;++end_flag) loc.push_back(hf[end_flag]);
    hf_flag = end_flag;
    auto res = solve(space, loc);
    up += res.first;
    down += res.second;
  }
  return down<=any_cnt&&any_cnt<=up;
}
signed main(){
  int T=read();
  while(T--) puts(work()?"TAK":"NIE");
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 0ms
memory: 3488kb

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: 105ms
memory: 22388kb

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'