QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#556369#9251. Graph Changingno_RED_no_DEADWA 0ms3644kbC++201.9kb2024-09-10 17:23:192024-09-10 17:23:21

Judging History

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

  • [2024-09-10 17:23:21]
  • 评测
  • 测评结果:WA
  • 用时:0ms
  • 内存:3644kb
  • [2024-09-10 17:23:19]
  • 提交

answer

#include "bits/stdc++.h"
using namespace std;
using ll = long long;

const ll N = 1e6 + 1;
const ll M = 1e9 + 7;

ll jump_x_y(ll x, ll y, ll n, ll k) {
    if (y - x >= k) return 1;
    return 1e18;
}

ll jump_x_1_y(ll x, ll y, ll n, ll k) {
    if (x - 1 >= k && y - 1 >= k) return 2;
    return 1e18;
}

ll jump_x_n_y(ll x, ll y, ll n, ll k) {
    if (n - x >= k && n - y >= k) return 2;
    return 1e18;
}

ll jump_x_n_1_y(ll x, ll y, ll n, ll k) {
    if (n - x >= k && n - 1 >= k && y - 1 >= k) return 3;
    return 1e18;
}

ll jump_x_1_n_y(ll x, ll y, ll n, ll k) {
    if (x - 1 >= k && n - 1 >= k && n - y >= k) return 3;
    return 1e18;
}

ll jump(ll x, ll y, ll n, ll k) {
    ll res = 1e18;
    res = min({
        jump_x_y(x, y, n, k),
        jump_x_1_y(x, y, n, k),
        jump_x_n_y(x, y, n, k),
        jump_x_1_n_y(x, y, n, k),
        jump_x_n_1_y(x, y, n, k),
    });
    if (res == 1e18) return -1;
    return res;
}

void doTest(ll testID) {
    ll t, n, k, x, y; cin >> t >> n >> k >> x >> y; if (x > y) swap(x, y);
    if (t == 0) {cout << y - x << '\n'; return;}
    if (t == 1) {cout << jump(x, y, n, k) << '\n'; return;}
    if (k == 1) {cout << "1\n"; return;}

    // TH1: k = 2 => BC = B0, BL = -1, 1, 2, 3
    if (k == 2) {
        if (n <= 2) {cout << "-1\n"; return;}
        if (n == 3) {cout << "-1\n"; return;}
        if (t % 2 == 0) {cout << y - x << '\n'; return;}
        else {cout << jump(x, y, n, k) << '\n'; return;}
    }

    // TH2: k = 3
    if (k == 3) {
        if (n >= 7 || n <= 5) {cout << "-1\n"; return;}
        if (t > 3) {cout << "-1\n"; return;}
        cout << ((x == 3 && y == 4) ? "1\n" : "-1\n"); return;
    }

    // TH3: k >= 4
    if (k >= 4) {cout << "-1\n"; return;}
}

signed main() {
    ios_base::sync_with_stdio(0); cin.tie(0);

    int test = 1; 
    cin >> test;
    for (int _ = 1; _ <= test; _ ++) doTest(test);
}

詳細信息

Test #1:

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

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: 3644kb

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: 0
Accepted
time: 0ms
memory: 3580kb

input:

90
1 3 1 1 2
1 3 1 1 3
1 3 1 2 3
1 3 2 1 2
1 3 2 1 3
1 3 2 2 3
1 3 3 1 2
1 3 3 1 3
1 3 3 2 3
1 3 4 1 2
1 3 4 1 3
1 3 4 2 3
1 3 5 1 2
1 3 5 1 3
1 3 5 2 3
1 3 6 1 2
1 3 6 1 3
1 3 6 2 3
2 3 1 1 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ok 180 lines

Test #5:

score: -100
Wrong Answer
time: 0ms
memory: 3580kb

input:

300
1 5 1 1 2
1 5 1 1 3
1 5 1 1 4
1 5 1 1 5
1 5 1 2 3
1 5 1 2 4
1 5 1 2 5
1 5 1 3 4
1 5 1 3 5
1 5 1 4 5
1 5 2 1 2
1 5 2 1 3
1 5 2 1 4
1 5 2 1 5
1 5 2 2 3
1 5 2 2 4
1 5 2 2 5
1 5 2 3 4
1 5 2 3 5
1 5 2 4 5
1 5 3 1 2
1 5 3 1 3
1 5 3 1 4
1 5 3 1 5
1 5 3 2 3
1 5 3 2 4
1 5 3 2 5
1 5 3 3 4
1 5 3 3 5
1 5 3 ...

output:

1
1
1
1
1
1
1
1
1
1
2
1
1
1
2
1
1
2
1
2
2
-1
1
1
-1
3
1
-1
-1
2
-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
1
1
1
1
1
1
1
1
1
1
1
2
3
4
1
2
3
1
2
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
-1
-1
-1
-1
-1
-1
-1...

result:

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