QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#552850 | #9251. Graph Changing | ucup-team180# | WA | 1ms | 3724kb | C++17 | 2.3kb | 2024-09-08 03:05:21 | 2024-09-08 03:05:22 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
int main(){
int q;
cin >> q;
for (int i = 0; i < q; i++){
int t, n, k, x, y;
cin >> t >> n >> k >> x >> y;
x--;
y--;
if (x > y){
swap(x, y);
}
if (t == 0){
cout << y - x << '\n';
} else if (t == 1){
if (y - x >= k){
cout << 1 << '\n';
} else if (max(x, n - 1 - x) < k || max(y, n - 1 - y) < k){
cout << -1 << '\n';
} else if (x >= k || n - 1 - y >= k){
cout << 2 << '\n';
} else {
cout << 3 << '\n';
}
} else {
if (k == 1){
cout << 1 << '\n';
} else if (k == 2){
if (n <= 3){
cout << -1 << '\n';
} else {
if (t % 2 == 0){
cout << y - x << '\n';
} else {
if (y - x >= 2){
cout << 1 << '\n';
} else if (x >= 2 || n - 1 - y >= 2){
cout << 2 << '\n';
} else {
cout << 3 << '\n';
}
}
}
} else if (k == 3){
if (n <= 4){
cout << -1 << '\n';
} else if (n == 5){
if (t == 2){
if (x == 1 && y == 3){
cout << 1 << '\n';
} else {
cout << -1 << '\n';
}
} else {
cout << -1 << '\n';
}
} else if (n == 6){
if (t == 2){
if (x == 1 && y == 3 || x == 2 && y == 3 || x == 2 && y == 4){
cout << 1 << '\n';
} else if (x == 1 && y == 2 || x == 3 && y == 4){
cout << 2 << '\n';
} else if (x == 1 && y == 4){
cout << 3 << '\n';
} else {
cout << -1 << '\n';
}
} else if (t == 3){
if (x == 1 && y == 4){
cout << 1 << '\n';
} else {
cout << -1 << '\n';
}
} else {
cout << -1 << '\n';
}
} else if (n == 7){
if (x == 2 && y == 4){
cout << 1 << endl;
} else {
cout << -1 << endl;
}
} else {
cout << -1 << '\n';
}
} else {
cout << -1 << '\n';
}
}
}
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 3652kb
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: 3724kb
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: 3548kb
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 2 2 3 1 1 3 2 3 1 2 3 2 3 2 1 2 2 3 2 1 3 2 3 2 2 3 2 3 3 1 2 2 3 3 1 3 2 3 3 2 3 2 3 4 1 2 2 3 4 1 3 2 3 4 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 -1 -1 -1 -1 -1 -1 1 1 1 -1 -1 -1 -1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