QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#697229 | #9251. Graph Changing | lllei | WA | 0ms | 3668kb | C++20 | 3.5kb | 2024-11-01 12:09:43 | 2024-11-01 12:09:44 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
using LL = long long;
void solve() {
int t, n, k, x, y;
cin >> t >> n >> k >> x >> y;
if (x > y) {
swap(x, y);
}
if (t == 0) {
cout << abs(x - y) << '\n';
return;
}
auto get = [&](int x, int y) {
if (abs(x - y) >= k) {
return 1;
} else if ((x - 1 >= k && y - 1 >= k) || (n - x >= k && n - y >= k)) {
return 2;
} else if ((x - 1 >= k && n - y >= k) || (n - x >= k && y - 1 >= k)) {
return 3;
} else {
return -1;
}
};
if (k == 1) {
cout << 1 << '\n';
} else if (k == 2) {
if (n == 2) {
cout << -1 << '\n';
} else if (n == 3) {
if (t == 1) {
if (x == 2 || y == 2) {
cout << -1 << '\n';
} else {
cout << 1 << '\n';
}
} else {
cout << -1 << '\n';
}
} else {
if (t % 2 == 0) {
cout << abs(x - y) << '\n';
} else {
get(x, y) << '\n';
}
}
} else if (k == 3) {
if (n >= 8) {
if (t >= 2) {
cout << -1 << '\n';
} else {
cout << get(x, y) << '\n';
}
} else if (n == 7) {
if (t == 1) {
cout << get(x, y) << '\n';
} else if (t == 2) {
if (x == 3 && y == 5) {
cout << 1 << '\n';
} else {
cout << -1 << '\n';
}
} else {
cout << -1 << '\n';
}
} else if (n == 6) {
if (t == 1) {
cout << get(x, y) << '\n';
} else if (t == 2) {
if ((x == 2 && y == 4) || (x == 3 && y == 5) || (x == 3 && y == 4)) {
cout << 1 << '\n';
} else if ((x == 2 && y == 3) || (x == 4 && y == 5)) {
cout << 2 << '\n';
} else if (x == 2 && y == 5) {
cout << 3 << '\n';
} else {
cout << -1 << '\n';
}
} else if (t == 3) {
if (x == 2 && y == 5) {
cout << 1 << '\n';
} else {
cout << -1 << '\n';
}
} else {
cout << -1 << '\n';
}
} else if (n == 5) {
if (t > 1) {
cout << -1 << '\n';
} else {
cout << get(x, y) << '\n';
}
} else if (n == 4) {
if (t == 2) {
if (x == 1 && y == 4) {
cout << 1 << '\n';
} else {
cout << -1 << '\n';
}
} else if (t == 1) {
cout << get(x, y) << '\n';
} else {
cout << -1 << '\n';
}
} else {
cout << -1 << '\n';
}
} else {
if (t >= 2) {
cout << -1 << '\n';
} else {
cout << get(x, y) << '\n';
}
}
}
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
int q;
cin >> q;
while (q--) {
solve();
}
return 0;
}
/*
1
1 4 2 2 3
*/
詳細信息
Test #1:
score: 100
Accepted
time: 0ms
memory: 3624kb
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: 3584kb
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: 3668kb
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 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