QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#657337#9251. Graph ChangingFiatiustitia#WA 0ms3972kbC++172.6kb2024-10-19 14:35:462024-10-19 14:35:51

Judging History

你现在查看的是最新测评结果

  • [2024-10-19 14:35:51]
  • 评测
  • 测评结果:WA
  • 用时:0ms
  • 内存:3972kb
  • [2024-10-19 14:35:46]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;
int T;
inline int read(){
    int ret=0;char ch=getchar();bool flg=0;
    while(!isdigit(ch)) flg^=!(ch^'-'),ch=getchar();
    while(isdigit(ch)) ret=(ret<<3)+(ret<<1)+ch-48,ch=getchar();
    return flg?-ret:ret;
}
void solve()
{
    int t=read(),n=read(),k=read(),x=read(),y=read();
    if(x>y) swap(x,y);
    if(t==0){
        printf("%d\n",(y-x));
        return;
    }
    if(k==1){
        printf("%d\n",1);
        return;
    }
    if(k==2){
        if(n<=3){
            if(t==1&&x==1&&y==3){
                printf("1\n");
                return;
            }
            printf("-1\n");
            return;
        }
        t&=1;
        if(t==0){
            printf("%d\n",(y-x));
            return;
        }
        else{
            if(y-x>=2){
                printf("1\n");
                return;
            }
            if(x>=3){
                printf("2\n");
                return;
            }
            printf("3\n");
            return;
            
        }
        return;
    }
    if(k==3){
        if(t>=3) {printf("-1\n");return;}
        if(t==1){
            if(y-x>=k){
                printf("1\n");
                return;
            }
            if(x>=k+1||y+k<=n){
                printf("2\n");
                return;
            }
            //x n 1 y
            
            if(n-x>=k&&y-1>=k){
                printf("3\n");
                return;
            }
            printf("-1\n");
            return;
        }
        if(t==2){
            if((x==2&&y==4)||(x==3&&y==5)){
                if(n-x>=k&&y-1>=k){
                    printf("1\n");
                    return;
                }
            }

            printf("-1\n");
            return;
        }
    }
    if(k>=4){
        if(t>=2) {printf("-1\n");return;}
        if(y-x>=k){
                printf("1\n");
                return;
            }
            if(x>=k+1||y+k<=n){
                printf("2\n");
                return;
            }
            //x n 1 y
            
            if(n-x>=k&&y-1>=k){
                printf("3\n");
                return;
            }
            printf("-1\n");
            return;
    }
}
int main()
{
#ifdef LOCAL
    freopen("data.in", "r", stdin);
    freopen("data.out", "w", stdout);
    auto _ = clock();
#endif
    // ios::sync_with_stdio(false);
    // cin.tie(nullptr);
    T=read();

    while(T--) solve();
#ifdef LOCAL
    cerr << clock() - _ << '\n';
#endif
    return 0;
}

详细

Test #1:

score: 100
Accepted
time: 0ms
memory: 3772kb

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: 3780kb

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: 3864kb

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
-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
-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
-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 90 lines

Test #4:

score: -100
Wrong Answer
time: 0ms
memory: 3972kb

input:

180
1 4 1 1 2
1 4 1 1 3
1 4 1 1 4
1 4 1 2 3
1 4 1 2 4
1 4 1 3 4
1 4 2 1 2
1 4 2 1 3
1 4 2 1 4
1 4 2 2 3
1 4 2 2 4
1 4 2 3 4
1 4 3 1 2
1 4 3 1 3
1 4 3 1 4
1 4 3 2 3
1 4 3 2 4
1 4 3 3 4
1 4 4 1 2
1 4 4 1 3
1 4 4 1 4
1 4 4 2 3
1 4 4 2 4
1 4 4 3 4
1 4 5 1 2
1 4 5 1 3
1 4 5 1 4
1 4 5 2 3
1 4 5 2 4
1 4 5 ...

output:

1
1
1
1
1
1
3
1
1
3
1
2
-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
1
2
3
1
2
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
1
3
1
1
3
1
2
-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
1...

result:

wrong answer 7th lines differ - expected: '2', found: '3'