QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#555149#9221. Missing BoundariesThe_Hallak#WA 0ms3616kbC++172.0kb2024-09-09 20:12:062024-09-09 20:12:06

Judging History

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

  • [2024-09-09 20:12:06]
  • 评测
  • 测评结果:WA
  • 用时:0ms
  • 内存:3616kb
  • [2024-09-09 20:12:06]
  • 提交

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;

vector<string> ans;

int solve() {
  int n;
  cin >> n;
  ll l;
  cin >> l;
  map<ll, ll> mp;
  mp[l + 1] = 1;
  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) {
      sum1++;
    }
  }
  for (auto x : mp)
    if (x.second > 1) {
      ans.emplace_back(NO);
      return 0;
    }
  if (n > l){
    ans.emplace_back(NO);
    return  0;
  }

  int cur = 1;
  ll need = 0, can = 0;
  while (mp.size() > 1) {
    int mn = mp.begin()->first;
    mp.erase(mp.begin());
    if (cur > mn){
      ans.emplace_back(NO);
      return  0;
    }
    if (mp1.count(mn)) {
      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;
        can+=cur-mn-1;
      }
    } else {
      can += mn - cur;
      cur = mn + 1;
    }
  }
  cout<<need<<" "<<cur<<" "<<can<<endline;
  if (cur != l + 1)
    need++, can += l - cur + 1;
  if (need <= sum1 && sum1 <= can)
    ans.emplace_back(YES);
  else
    ans.emplace_back(NO);
  return 0;
}

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


*/

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 0
Wrong Answer
time: 0ms
memory: 3616kb

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:

0 51 8
TAK
NIE
NIE

result:

wrong answer 1st lines differ - expected: 'TAK', found: '0 51 8'