QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#656193#9251. Graph ChangingjieloscWA 0ms3680kbC++202.6kb2024-10-19 11:44:292024-10-19 11:44:46

Judging History

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

  • [2024-10-19 11:44:46]
  • 评测
  • 测评结果:WA
  • 用时:0ms
  • 内存:3680kb
  • [2024-10-19 11:44:29]
  • 提交

answer

#include <bits/stdc++.h>
#define int int64_t

using std::cin;
using std::cout;
const char endl = '\n';

void solve() {
  int t, n, k, x, y;
  cin >> t >> n >> k >> x >> y;
  if (x > y) std::swap(x, y);
  int min = std::min(x, y), max = std::max(x, y);
  if (t == 0) {
    cout << abs(x - y) << endl;
    return;
  }
  if (t == 1) {
    if ((abs(x - y) >= k))
      cout << 1 << endl;
    else if (
      (abs(1 - x) >= k and abs(1 - y) >= k) or
      (abs(x - n) >= k and abs(y - n) >= k))
      cout << 2 << endl;
    else if (std::max(x - 1, n - x) >= k and std::max(y - 1, n - y) >= k)
      cout << 3 << endl;
    else
      cout << -1 << endl;
    return;
  }
  // second kong!
  // t >= 2
  if (n <= k or k >= 4) {
    cout << -1 << endl;
    return;
  }
  if (k == 3) {
    if (n == 6) {
      if (t == 2) {
        if (x == 2 and y == 3)
          cout << 2 << endl;
        else if (x == 2 and y == 4)
          cout << 1 << endl;
        else if (x == 2 and y == 5)
          cout << 3 << endl;
        else if (x == 3 and y == 4)
          cout << 1 << endl;
        else if (x == 3 and y == 5)
          cout << 1 << endl;
        else if (x == 4 and y == 5)
          cout << 2 << endl;
        else
          cout << -1 << endl;
      } else if (t == 3) {
        if (x == 2 and y == 5)
          cout << 1 << endl;
        else
          cout << -1 << endl;
      } else
        cout << -1 << endl;
      return;
    }
    if (n == 4)
      cout << -1 << endl;
    else if (n >= 5 and n <= 7) {
      if (t == 2) {
        if (n == 5 and (x == 2 and y == 4))
          cout << 1 << endl;
        else if (n == 7 and min == 3 and max == 5)
          cout << 1 << endl;
        else
          cout << "-1\n";
      } else
        cout << "-1\n";
    } else
      cout << "-1\n";
  }
  if (k == 2) {
    if (n <= 3) cout << "-1\n";
    if (t & 1) {
      if ((abs(x - y) >= k))
        cout << 1 << endl;
      else if (
        (abs(1 - x) >= k and abs(1 - y) >= k) or
        (abs(x - n) >= k and abs(y - n) >= k))
        cout << 2 << endl;
      else if (std::max(x - 1, n - x) >= k and std::max(y - 1, n - y) >= k)
        cout << 3 << endl;
      else
        cout << -1 << endl;
    } else
      cout << abs(x - y) << endl;
  }
  if (k == 1) cout << 1 << endl;
}

int32_t main() {
#ifndef _DEBUG
  std::ios::sync_with_stdio(false);
  std::cin.tie(nullptr);
#endif
  int tc = 1;
  std::cin >> tc;
  while (tc--) solve();
#ifdef _DEBUG
  std::cout << std::endl;
  std::cout << "Time used: " << clock() << "ms" << std::endl;
  system("pause");
  return 0;
#endif
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

input:

5
1 5 3 2 4
1 10 4 2 4
2 10 5 2 4
1 3 2 1 3
1 3 2 1 2

output:

3
2
-1
1
-1

result:

ok 5 lines

Test #2:

score: 0
Accepted
time: 0ms
memory: 3680kb

input:

30
1 2 1 1 2
1 2 2 1 2
1 2 3 1 2
1 2 4 1 2
1 2 5 1 2
1 2 6 1 2
2 2 1 1 2
2 2 2 1 2
2 2 3 1 2
2 2 4 1 2
2 2 5 1 2
2 2 6 1 2
3 2 1 1 2
3 2 2 1 2
3 2 3 1 2
3 2 4 1 2
3 2 5 1 2
3 2 6 1 2
4 2 1 1 2
4 2 2 1 2
4 2 3 1 2
4 2 4 1 2
4 2 5 1 2
4 2 6 1 2
5 2 1 1 2
5 2 2 1 2
5 2 3 1 2
5 2 4 1 2
5 2 5 1 2
5 2 6 1 2

output:

1
-1
-1
-1
-1
-1
1
-1
-1
-1
-1
-1
1
-1
-1
-1
-1
-1
1
-1
-1
-1
-1
-1
1
-1
-1
-1
-1
-1

result:

ok 30 lines

Test #3:

score: -100
Wrong Answ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