QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#656152 | #9251. Graph Changing | jielosc | WA | 0ms | 3716kb | C++20 | 2.1kb | 2024-10-19 11:35:45 | 2024-10-19 11:35:45 |
Judging History
answer
#include <bits/stdc++.h>
#define int int64_t
using std::cin;
using std::cout;
const char endl = '\n';
void solve() {
int t, n, k, x, y;
cin >> t >> n >> k >> x >> y;
if (x > y) std::swap(x, y);
int min = std::min(x, y), max = std::max(x, y);
if (t == 0) {
cout << abs(x - y) << endl;
return;
}
if (t == 1) {
if ((abs(x - y) >= k))
cout << 1 << endl;
else if (
(abs(1 - x) >= k and abs(1 - y) >= k) or
(abs(x - n) >= k and abs(y - n) >= k))
cout << 2 << endl;
else if (std::max(x - 1, n - x) >= k and std::max(y - 1, n - y) >= k)
cout << 3 << endl;
else
cout << -1 << endl;
return;
}
// second kong!
// t >= 2
if (n <= k or k >= 4) {
cout << -1 << endl;
return;
}
if (k == 3) {
if (n == 4)
cout << -1 << endl;
else if (n >= 5 and n <= 7) {
if (t == 2) {
if (n == 5 and (min == 2 and max == 4))
cout << 3 << endl;
else if (
n == 6 and
((min == 3 and max == 4) or (min == 2 and max == 4) or
(min == 3 and max == 5)))
cout << 3 << endl;
else if (n == 7 and min == 3 and max == 5)
cout << 3 << endl;
else
cout << "-1\n";
} else
cout << "-1\n";
} else
cout << "-1\n";
}
if (k == 2) {
if (n <= 3) cout << "-1\n";
if (t & 1) {
if ((abs(x - y) >= k))
cout << 1 << endl;
else if (
(abs(1 - x) >= k and abs(1 - y) >= k) or
(abs(x - n) >= k and abs(y - n) >= k))
cout << 2 << endl;
else if (std::max(x - 1, n - x) >= k and std::max(y - 1, n - y) >= k)
cout << 3 << endl;
else
cout << -1 << endl;
} else
cout << abs(x - y) << endl;
}
if (k == 1) cout << 1 << endl;
}
int32_t main() {
#ifndef _DEBUG
std::ios::sync_with_stdio(false);
std::cin.tie(nullptr);
#endif
int tc = 1;
std::cin >> tc;
while (tc--) solve();
#ifdef _DEBUG
std::cout << std::endl;
std::cout << "Time used: " << clock() << "ms" << std::endl;
system("pause");
return 0;
#endif
}
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: 3716kb
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: -100
Wrong Answer
time: 0ms
memory: 3664kb
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 -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