QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#555088#9221. Missing BoundariesThe_Hallak#WA 211ms34720kbC++171.8kb2024-09-09 19:46:272024-09-09 19:46:28

Judging History

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

  • [2024-09-09 19:46:28]
  • 评测
  • 测评结果:WA
  • 用时:211ms
  • 内存:34720kb
  • [2024-09-09 19:46:27]
  • 提交

answer

#include <bits/stdc++.h>

#define speed                                                                  \
  ios_base::sync_with_stdio(0);                                                \
  cin.tie(0);                                                                  \
  cout.tie(0)
#define ll long long
#define YES "TAK"
#define NO "NIE"
#define endline '\n'

using namespace std;

const ll N = 5e5 + 10, MM = 998244353, MAX = 1e18;

int solve() {
  int n;
  cin >> n;
  ll l;
  cin >> l;
  map<ll, ll> mp;
  map<ll, ll> mp1, mp2;
  ll sum = 0, sum1 = 0;
  for (int i = 0; i < n; i++) {
    int a, b;
    cin >> a >> b;
    if (a + 1) {
      mp[a]++;
      mp1[a] = b;
    }
    if (b + 1 && a != b) {
      mp[b]++;
      mp2[b] = a;
    }
    if (a == -1 && b == -1) {
      sum++;
      sum1++;
    } else if (a + 1 && b + 1) {
      sum += b - a + 1;
    }
  }
  for (auto x : mp)
    if (x.second > 1)
      return cout << NO << endline, 0;
  if (sum > l)
    return cout << NO << endline, 0;

  int cur = 1;
  ll need = 0, can = 0;
  while (mp.size()) {
    int mn = mp.begin()->first;
    mp.erase(mp.begin());
    if (mp1.count(mn)) {
      if(cur>mn)return cout<<NO<<endline,0;
      if (cur != mn){
        need++, can += mn - cur;
      }
      int nxt = mp1[mn];
      if (nxt != -1) {
        mp.erase(nxt);
        cur = nxt + 1;
      } else {
        cur = mp.begin()->first;
      }
    } else {
      can += mn - cur;
      cur = mn + 1;
    }
  }
  if (cur==l&&need <= sum1)
    cout << YES << endline;
  else
    cout << NO << endline;
  return 0;
}

int main() {
  speed;
  int t = 1;
  cin >> t;
  int i = 1;
  while (t--) {
    // cout << "Case #" << i++ << ": ";
    solve();
  }
  return 0;
}
/*


*/

详细

Test #1:

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

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: 211ms
memory: 34720kb

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'