QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#656338#9251. Graph ChangingjieloscWA 0ms3660kbC++202.6kb2024-10-19 12:25:412024-10-19 12:25:45

Judging History

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

  • [2024-10-19 12:25:45]
  • 评测
  • 测评结果:WA
  • 用时:0ms
  • 内存:3660kb
  • [2024-10-19 12:25:41]
  • 提交

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 (k >= 4 or n <= k + 1) {
    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 >= 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: 3660kb

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: -100
Wrong Answer
time: 0ms
memory: 3628kb

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:

wrong answer 7th lines differ - expected: '1', found: '-1'