QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#687491 | #9251. Graph Changing | Flica# | WA | 0ms | 3708kb | C++17 | 7.3kb | 2024-10-29 19:20:06 | 2024-10-29 19:20:07 |
Judging History
answer
#include <bits/stdc++.h>
long long q, t, n, k, x, y;
void solve() {
std::cin >> t >> n >> k >> x >> y;
if (k == 1) {
if (t == 0) {
std::cout << std::abs(x - y) << '\n';
return;
} else std::cout << 1 << '\n';
return;
} else if (k == 2) {
if (n <= 3) {
if (t >= n - 1) {
std::cout << -1 << '\n';
} else {
if (t == 0) {
std::cout << std::abs(x - y) << '\n';
return;
} else if (t == 1) {
if (std::abs(x - y) >= 2) {
std::cout << 1 << '\n';
return;
} else {
std::cout << -1 << '\n';
return;
}
}
}
} else {
long long flag = t % 2;
if (flag == 0) {
std::cout << std::abs(x - y) << '\n';
return;
} else {
if (std::abs(x - y) >= k) {
std::cout << 1 << '\n';
return;
} else {
if (n == 4) {
if (std::min(x, y) == 2) std::cout << 3 << '\n';
else std::cout << 2 << '\n';
return;
} else {
std::cout << 2 << '\n';
return;
}
}
}
}
} else if (k >= 4){
if (t == 0) {
std::cout << std::abs(x - y) << '\n';
return;
} else {
if (t >= 2) {
std::cout << -1 << '\n';
return;
} else {
if (std::abs(x - y) >= k) {
std::cout << 1 << '\n';
return;
} else {
if (std::min(x, y) >= (n + 1) / 2 || std::max(x, y) <= n / 2) {
if (std::max(n - std::max(x, y), std::min(x, y)) >= k) {
std::cout << 2 << '\n';
return;
} else {
std::cout << -1 << '\n';
return;
}
} else {
long long lit = std::min(x, y);
long long hu = std::max(x, y);
if (n - lit >= k) {
if (n - hu >= k) {
std::cout << 2 << '\n';
return;
}
if (n >= k) {
if (hu >= k) {
std::cout << 3 << '\n';
return;
}
}
}
if (hu >= k) {
if (lit >= k) {
std::cout << 2 << '\n';
return;
}
if (n >= k) {
if (n - lit >= k) {
std::cout << 3 << '\n';
return;
}
}
}
std::cout << -1 << '\n';
return;
}
}
}
}
} else {
if (t == 0) {
std::cout << std::abs(x - y) << '\n';
return;
} else if (n <= 3 && t >= 1) {
std::cout << -1 << '\n';
return;
} else {
if (n == 4) {
if (t >= 2) {
std::cout << -1 << '\n';
return;
} else {
if (std::abs(x - y) >= 3) {
std::cout << 1 << '\n';
return;
} else {
std::cout << -1 << '\n';
return;
}
}
} else if (n == 5) {
if (t >= 2) {
if (std::min(x, y) == 2 && std::max(x, y) == 4 && t == 2) std::cout << 1 << '\n';
else std::cout << -1 << '\n';
return;
} else {
if (std::abs(x - y) >= 3) {
std::cout << 1 << '\n';
return;
} else {
long long lit = std::min(x, y);
long long hu = std::max(x, y);
if (lit == 1 && hu == 2) std::cout << 2 << '\n';
else if (lit == 2 && hu == 4) std::cout << 3 << '\n';
else if (lit == 4 && hu == 5) std::cout << 2 << '\n';
else std::cout << -1 << '\n';
return;
}
}
} else if (n == 6) {
if (t >= 3) {
std::cout << -1 << '\n';
return;
} else if (t == 1) {
if (std::abs(x - y) >= 3) {
std::cout << 1 << '\n';
return;
} else {
long long lit = std::min(x, y);
long long hu = std::max(x, y);
if ((lit == 2 && hu == 4) || (lit == 3 && hu == 5)) std::cout << 3 << '\n';
else std::cout << 2 << '\n';
return;
}
} else {
long long lit = std::min(x, y);
long long hu = std::max(x, y);
if ((lit == 2 && hu == 4) || (lit == 3 && hu == 5)) std::cout << 1 << '\n';
else std::cout << -1 << '\n';
return;
}
} else if (n == 7) {
if (t >= 3) {
std::cout << -1 << '\n';
return;
} else if (t == 1) {
long long lit = std::min(x, y);
long long hu = std::max(x, y);
if (lit == 3 && hu == 5) std::cout << 3 << '\n';
else std::cout << 2 << '\n';
return;
} else {
long long lit = std::min(x, y);
long long hu = std::max(x, y);
if (lit == 3 && hu == 5) std::cout << 1 << '\n';
else std::cout << -1 << '\n';
return;
}
} else {
if (t >= 2) {
std::cout << -1 << '\n';
return;
} else {
std::cout << 2 << '\n';
return;
}
}
}
}
}
int main() {
std::cin.tie(0)->sync_with_stdio(0);
std::cin >> q;
for (int i = 1; i <= q; i++) {
solve();
}
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 3592kb
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: 3708kb
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: 3700kb
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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