QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#617331#9251. Graph Changingucup-team4153#WA 0ms3604kbC++203.5kb2024-10-06 14:58:202024-10-06 14:58:20

Judging History

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

  • [2024-10-06 14:58:20]
  • 评测
  • 测评结果:WA
  • 用时:0ms
  • 内存:3604kb
  • [2024-10-06 14:58:20]
  • 提交

answer

#include<bits/stdc++.h>

using namespace std;

int solve0(int n, int k, int x, int y) {
    return abs(x - y);
}

int solve1(int n, int k, int x, int y) {
    if (abs(x - y) >= k)return 1;
    if ((abs(x - 1) >= k && abs(1 - y) >= k) || ((abs(x - n) >= k && abs(n - y) >= k)))return 2;
    if ((abs(x - 1) >= k && abs(1 - n) >= k && abs(n - y) >= k) ||
        (abs(x - n) >= k && abs(n - 1) >= k && abs(1 - y) >= k))
        return 3;
    return -1;
}

signed main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    int q;
    cin >> q;
    while (q--) {
        int t, n, k, x, y;
        cin >> t >> n >> k >> x >> y;
        if (t == 0) {
            cout << solve0(n, k, x, y) << '\n';
            continue;
        } else if (t == 1) {
            cout << solve1(n, k, x, y) << '\n';
            continue;
        }
        if (k == 1) {
            cout << 1 << '\n';
        } else if (k == 2) {
            if (n <= 3) {
                cout << -1 << '\n';
            } else {
                if (t & 1)cout << solve1(n, k, x, y) << '\n';
                else cout << solve0(n, k, x, y) << "\n";
            }
        } else if (k == 3) {
            if (n == 6) {
                if (t == 2) {
                    if (x == 2) {
                        if (y == 4)cout << 1 << '\n';
                        else if (y == 3)cout << 2 << '\n';
                        else if (y == 5)cout << 3 << '\n';
                        else cout << -1 << '\n';
                    } else if (x == 4) {
                        if (y == 2)cout << 1 << '\n';
                        else if (y == 3)cout << 1 << '\n';
                        else if (y == 5)cout << 2 << '\n';
                        else cout << -1 << '\n';
                    } else if (x == 3) {
                        if (y == 2)cout << 2 << '\n';
                        else if (y == 4)cout << 1 << '\n';
                        else if (y == 5)cout << 1 << '\n';
                        else cout << -1 << '\n';
                    } else if (x == 5) {
                        if (y == 2)cout << 3 << '\n';
                        else if (y == 4)cout << 2 << '\n';
                        else if (y == 3)cout << 1 << '\n';
                        else cout << -1 << '\n';
                    } else {
                        cout << -1 << '\n';
                    }
                } else if (t == 3) {
                    if ((x == 2 && y == 5) || (x == 5 || y == 2)) {
                        cout << 1 << '\n';
                    } else {
                        cout << -1 << '\n';
                    }
                } else {
                    cout << -1 << '\n';
                }
            } else if (n >= 4 && n <= 7 && t == 2) {
                if (n == 4) {
                    cout << -1 << '\n';
                } else if (n == 5) {
                    if ((x == 2 && y == 4) || (x == 4 || y == 2)) {
                        cout << 1 << '\n';
                    } else {
                        cout << -1 << '\n';
                    }
                } else if (n == 7) {
                    if ((x == 3 && y == 5) || (x == 5 || y == 3)) {
                        cout << 1 << '\n';
                    } else {
                        cout << -1 << '\n';
                    }
                }
            } else {
                cout << -1 << '\n';
            }
        } else {
            cout << -1 << '\n';
        }
    }
    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

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

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

result:

ok 180 lines

Test #5:

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

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
-1...

result:

wrong answer 81st lines differ - expected: '-1', found: '1'