QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#641649 | #9251. Graph Changing | ucup-team4479 | WA | 1ms | 3708kb | C++23 | 1.6kb | 2024-10-14 21:52:54 | 2024-10-14 21:52:54 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
int t, n, k, x, y;
int ans[10][5][10][10]; // n, t, x, y, k = 3
void ask(int x, int y) {
if (abs(x - y) >= k) cout << 1 << endl;
else if (x - 1 >= k || n - y >= k) cout << 2 << endl;
else if (n - x >= k && y - 1 >= k) cout << 3 << endl;
else cout << -1 << endl;
}
void solve() {
cin >> t >> n >> k >> x >> y;
if (x > y) swap(x, y);
if (n == 1) {
cout << 0 << endl;
return;
}
if (t == 0) {
cout << abs(x - y) << endl;
return;
}
if (k == 1) {
cout << 1 << endl;
return;
}
if (k > 3 && t > 1) {
cout << -1 << endl;
return;
}
if (t == 1) {
ask(x, y);
return;
}
if (k == 2) {
if (n >= 4) {
if (t & 1) ask(x, y);
else cout << abs(x - y) << endl;
} else if (n == 3) {
if (t == 2 && x == 1 && y == 3) cout << 1 << endl;
else cout << -1 << endl;
} else if (n == 2) {
cout << -1 << endl;
}
return;
}
if (k == 3) {
if (n >= 8 || t > 3) cout << -1 << endl;
else cout << ans[n][t][x][y] << endl;
}
}
int main() {
memset(ans, -1, sizeof(ans));
ans[7][2][3][5] = 1;
ans[6][2][2][4] = ans[6][2][3][4] = ans[6][2][3][5] = 1;
ans[6][2][2][3] = ans[6][2][4][5] = 2;
ans[6][2][2][5] = 3;
ans[6][3][2][5] = 1;
ans[5][2][2][4] = 1;
int q;
cin >> q;
while (q--) solve();
return 0;
}
/*
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
*/
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 3708kb
input:
5 1 5 3 2 4 1 10 4 2 4 2 10 5 2 4 1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