QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#688901 | #9251. Graph Changing | real_sigma_team# | WA | 0ms | 3860kb | C++23 | 1.9kb | 2024-10-30 14:13:29 | 2024-10-30 14:13:33 |
Judging History
answer
#include<bits/stdc++.h>
int main() {
std::cin.tie(nullptr)->sync_with_stdio(false);
int q;
std::cin >> q;
while (q--) {
int64_t t, n, k, x, y;
std::cin >> t >> n >> k >> x >> y;
if (x > y) std::swap(x, y);
if (t == 0) std::cout << std::abs(x - y) << '\n';
else if (k == 1) std::cout << "1\n";
else if (k == 2) {
if (n == 2) std::cout << "-1\n";
else if (n == 3) {
if (t == 1 && x == 1 && y == 3) std::cout << "1\n";
else std::cout << "-1\n";
} else if (n == 4 && t % 2 == 1 && x == 2 && y == 3) {
std::cout << "3\n";
} else if (t % 2 == 0) std::cout << std::abs(x - y) << '\n';
else std::cout << (std::abs(x - y) == 1 ? 2 : 1) << '\n';
} else if (t == 1) {
if (std::abs(x - y) >= k) std::cout << "1\n";
else if (std::max(n - x, x - 1) < k || std::max(n - y, y - 1) < k) std::cout << "-1\n";
else if (std::min(n - x, n - y) >= k || std::min(x - 1, y - 1) >= k) std::cout << "2\n";
else std::cout << "3\n";
} else if (k > 3) {
std::cout << "-1\n";
} else if (k == 3) {
if (t > 2) std::cout << "-1\n";
else {
if (n > 8) std::cout << "-1\n";
else {
std::vector<std::vector<int>> a(n, std::vector<int>(n, 1e9));
for (int i = 0; i + 1 < n; ++i) a[i][i + 1] = a[i + 1][i] = 1;
for (int iter = 0; iter <= t; ++iter) {
for (int i = 0; i < n; ++i) {
for (int j = 0; j < n; ++j) {
for (int k = 0; k < n; ++k) {
a[j][k] = std::min(a[j][k], a[j][i] + a[i][k]);
}
}
}
if (iter == t) break;
for (int i = 0; i < n; ++i) {
for (int j = 0; j < n; ++j) {
if (a[i][j] != 1e9 && a[i][j] >= k) a[i][j] = 1;
else a[i][j] = 1e9;
}
}
}
--x, --y;
if (a[x][y] == 1e9) std::cout << "-1\n";
else std::cout << a[x][y] << '\n';
}
}
} else {
assert(false);
}
}
}
詳細信息
Test #1:
score: 100
Accepted
time: 0ms
memory: 3572kb
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: 3552kb
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: 3652kb
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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