QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#657492#9251. Graph ChangingFiatiustitia#WA 1ms3868kbC++172.9kb2024-10-19 14:51:412024-10-19 14:51:46

Judging History

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

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

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>=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;
        }
        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(y-x>=k){
                printf("-1\n");
                return;
            }
            if(x>=k+1||y+k<=n){
                printf("-1\n");
                return;
            }
            //x n 1 y
            
            if(n-x>=k&&y-1>=k){
                printf("3\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: 3728kb

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

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

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

result:

ok 180 lines

Test #5:

score: -100
Wrong Answer
time: 1ms
memory: 3792kb

input:

300
1 5 1 1 2
1 5 1 1 3
1 5 1 1 4
1 5 1 1 5
1 5 1 2 3
1 5 1 2 4
1 5 1 2 5
1 5 1 3 4
1 5 1 3 5
1 5 1 4 5
1 5 2 1 2
1 5 2 1 3
1 5 2 1 4
1 5 2 1 5
1 5 2 2 3
1 5 2 2 4
1 5 2 2 5
1 5 2 3 4
1 5 2 3 5
1 5 2 4 5
1 5 3 1 2
1 5 3 1 3
1 5 3 1 4
1 5 3 1 5
1 5 3 2 3
1 5 3 2 4
1 5 3 2 5
1 5 3 3 4
1 5 3 3 5
1 5 3 ...

output:

1
1
1
1
1
1
1
1
1
1
2
1
1
1
2
1
1
2
1
2
2
-1
1
1
-1
3
1
-1
-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
1
1
1
1
1
1
1
1
1
1
2
3
4
1
2
3
1
2
1
-1
-1
-1
-1
-1
3
-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 86th lines differ - expected: '1', found: '3'