QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#674749 | #9251. Graph Changing | woodie_0064# | WA | 1ms | 3628kb | C++20 | 2.3kb | 2024-10-25 17:23:04 | 2024-10-25 17:23:05 |
Judging History
answer
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
const int N = 1e5 + 3;
int T;
int n, num;
void work(){
int q;cin >> q;
while(q--) {
int t,n,k,x,y;cin >> t >> n >> k >> x >> y;
if(x < y) swap(x,y);
if(t == 0) {
cout << x - y << '\n';
continue;
}
if(k == 1) {
cout << "1\n";
continue;
}
if(n == 2) {
cout << "-1\n";
continue;
}
if(n == 3) {
if(k >= 3) cout << "-1\n";
else if(k == 2){
if(t > 1) cout << "-1\n";
else {
if(x == 2 || y == 2) cout << "-1\n";
else cout << "1\n";
}
}
continue;
}
if(k == 2) {
if(t % 2 == 0) cout << x - y << '\n';
else cout << (x - y == 1 ? 2 : 1) << '\n';
continue;
}
if(k == 3) {
if(n >= 7) {
if(t == 1) cout << (x - y > k ? 1 : 2) << '\n';
else cout << "-1\n";
}else {
t += 1;
vector <vector <int>> f((n + 1),vector <int> (n + 1,1000));
for(int i = 1;i < n;i++) f[i][i + 1] = f[i + 1][i] = 1;
for(int i = 1;i <= n;i++) f[i][i] = 0;
while(t--) {
for(int i = 1;i <= n;i++) {
for(int j = 1;j <= n;j++) {
for(int k = 1;k <= n;k++) f[j][k] = min(f[j][k],f[j][i] + f[i][k]);
}
}
if(t == 0) break;
vector <vector <int>> g((n + 1),vector <int> (n + 1,1000));
bool flag = false;
for(int i = 1;i <= n;i++) {
for(int j = 1;j <= n;j++) {
if(f[i][j] >= k) {
g[i][j] = 1;
flag = true;
}
}
}
f = g;
for(int i = 1;i <= n;i++) f[i][i] = 0;
if(!flag) break;
}
// cout << f[x][y] << '\n';
if(f[x][y] >= n) f[x][y] = -1;
cout << f[x][y] << '\n';
}
continue;
}
if(k >= 4) {
if(t != 1) cout << "-1\n";
else {
auto check = [&] (int x) {
return x <= k && x > n - k;
};
if(x - y >= k) cout << "1\n";
else if(check(x) || check(y)) cout << "-1\n";
else {
if(x <= n - k && y <= n - k)cout << "2\n";
else if(x > k && y > k) cout << "2\n";
else cout << "3\n";
}
}
continue;
}
}
}
int main(){
// freopen("test.txt", "r", stdin);
ios::sync_with_stdio(false);
cin.tie(0);
// cin >> T;
// while(T--){
work();
// }
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 1ms
memory: 3628kb
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: 3604kb
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: 3616kb
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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