QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#687534 | #9251. Graph Changing | Flica# | WA | 0ms | 3708kb | C++17 | 7.7kb | 2024-10-29 19:32:29 | 2024-10-29 19:32:30 |
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';
return;
} 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);
long long ans = 999;
if (n - lit >= k) {
if (n - hu >= k) {
// std::cout << 2 << '\n';
// return;
ans = std::min(ans, 2ll);
}
if (n >= k) {
if (hu >= k) {
// std::cout << 3 << '\n';
// return;
ans = std::min(ans, 3ll);
}
}
}
if (hu >= k) {
if (lit >= k) {
// std::cout << 2 << '\n';
// return;
ans = std::min(ans, 2ll);
}
if (n >= k) {
if (n - lit >= k) {
// std::cout << 3 << '\n';
// return;
ans = std::min(ans, 3ll);
}
}
}
if (ans > 3) std::cout << -1 << '\n';
else std::cout << ans << '\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;
}
詳細信息
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: 3648kb
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: 3704kb
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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