QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#760672 | #9251. Graph Changing | liuyicheng | RE | 0ms | 0kb | C++17 | 1.6kb | 2024-11-18 18:19:32 | 2024-11-18 18:19:34 |
answer
#include <iostream>
#include <cstdio>
using namespace std;
void solve() {
int t, n, k, x, y;
cin >> t >> n >> k >> x >> y;
if (x < y) swap(x, y);
if (!t) cout << x - y;
else if (k >= n) cout << -1;
else if (k == 1) cout << 1;
else if (n == 3) cout << (t == 1 && x == 3 && y == 1 ? 1 : -1);
else if (t == 1) {
if (x - y >= k) cout << 1;
else if (x <= k && x + k > n || y <= k && y + k > n) cout << -1;
else if (y > k || x + k <= n) cout << 2;
else cout << 3;
} else if (k == 2) {
if (t & 1 ^ 1) cout << x - y;
else if (x - y >= 2) cout << 1;
else if (n == 4) {
if (x == 3 && y == 2) cout << 3;
else cout << 2;
} else cout << 2;
} else if (k == 3 && n == 4 && t == 1) cout << (x - y == 3 ? 1 : -1);
else if (k == 3 && n == 5) {
if (t == 2 && x == 4 && y == 2) cout << 1;
else cout << -1;
} else if (k == 3 && n == 6){
if (t == 2) {
if (x == 6 || y == 1) cout << -1;
else if (x == 5 && y == 2) cout << 3;
else if (x == 3 && y == 2 || x == 5 && y == 4) cout << 2;
else cout << 1;
} else if (t == 3) cout << (x == 5 && y == 2 ? 1 : -1);
else cout << -1;
} else if (k == 3 && n == 7 && t == 2 && x == 5 && y == 3) cout << 1;
else cout << -1;
cout << '\n';
}
signed main() {
freopen("graph.in", "r", stdin);
freopen("graph.out", "w", stdout);
ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);
int T; cin >> T;
while (T--) solve();
}
详细
Test #1:
score: 0
Dangerous Syscalls
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