QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#682946 | #9251. Graph Changing | louhao088 | WA | 1ms | 3852kb | C++98 | 2.7kb | 2024-10-27 18:03:50 | 2024-10-27 18:03:52 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
const int MAXQ=1e6,MAXV=1e9;
const int Code[]={0,2,4,0,1,3};
const int Code2[]={0,0,1,3,2,4};
inline int ABS(int x) {return x>0 ? x : -x;}
int q,t,n,K,x,y;
int dis[7][7];
int main()
{
dis[1][2] = 2; dis[1][3] = 2; dis[1][4] = 1; dis[1][5] = 1; dis[1][6] = 1;
dis[2][3] = 2; dis[2][4] = 3; dis[2][5] = 1; dis[2][6] = 1;
dis[3][4] = 3; dis[3][5] = 3; dis[3][6] = 1;
dis[4][5] = 2; dis[4][6] = 2;
dis[5][6] = 2;
scanf("%d",&q);
while(q--)
{
scanf("%d %d %d %d %d",&t,&n,&K,&x,&y);
if(x>y) swap(x,y);
if(t==0) {printf("%d\n",y-x);continue;}
if(n<=K) {puts("-1");continue;}
if(K==1) {puts("1");continue;}
if(K==2)
{
if(n==3)
{
if(t==1 && x==1 && y==3) puts("1");
else puts("-1");
continue;
}
if(t&1)
{
if(y-x>=K) {puts("1");continue;}
if((x-1>=K && y-1>=K) || (n-x>=K && n-y>=K)) {puts("2");continue;}
puts("3");
}
else printf("%d\n",y-x);
continue;
}
if(K>=4)
{
if(t==1)
{
if(x-1<K&&n-x<K){puts("-1");continue;}
if(y-1<K&&n-y<K){puts("-1");continue;}
if(y-x>=K) {puts("1");continue;}
if((x-1>=K && y-1>=K) || (n-x>=K && n-y>=K)) {puts("2");continue;}
puts("3");
}
else puts("-1");
continue;
}
if(n>7)
{
if(t==1)
{
if(y-x>=K) puts("1");
else puts("2");
}
else puts("-1");
continue;
}
if(n==4)
{
if(t==1 && x==1 && y==4) puts("1");
else puts("-1");
continue;
}
if(n==5)
{
if(t==1)
{
if(x==3 || y==3) {puts("-1");continue;}
printf("%d\n",ABS(Code[x]-Code[y]));
}
else if(t==2 && x==2 && y==4) puts("1");
else puts("-1");
continue;
}
if(t>3) {puts("-1");continue;}
if(t==2)
{
if(1<x && y<6) printf("%d\n",ABS(Code2[x]-Code2[y]));
else puts("-1");
continue;
}
if(t==3)
{
if(x==2 && y==5) puts("1");
else puts("-1");
}
if(t==1)
{
// if (x > y) swap(x, y);
printf("%d\n", dis[x][y]);
}
}
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 3848kb
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: 3648kb
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: 3656kb
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 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