QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#593391#9251. Graph Changingucup-team4352#WA 0ms3560kbC++232.1kb2024-09-27 13:43:172024-09-27 13:43:19

Judging History

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

  • [2024-09-27 13:43:19]
  • 评测
  • 测评结果:WA
  • 用时:0ms
  • 内存:3560kb
  • [2024-09-27 13:43:17]
  • 提交

answer

#include<bits/stdc++.h>
#define ll long long
#define pii pair<ll,ll>
#define lowbit(x) (x&-x)
#define log(x) (31^__builtin_clz(x))
using namespace std;

ll t,n,k,x,y;
ll calc(ll a,ll b){
    if(abs(a-b)>=k)return 1;
    if((a-1>k&&n-a>k)||(b-1>k&&n-b>k))return -1;
    if((a-1>=k&&b-1>=k)||(n-a>=k&&n-b>=k))return 2;
    return 3;
}
void solve(){
    cin>>t>>n>>k>>x>>y;
    if(x>y)swap(x,y);
    if(t==0){
        cout<<y-x<<"\n";
        return;
    }
    if(k==1){
        cout<<"1\n";
        return;
    }
    if(k==2){
        if(n==2){
            cout<<"-1\n";
            return;
        }
        if(n==3){
            if(t==1&&x==1&&y==3)cout<<"1\n";
            else cout<<"-1\n";
            return;
        }
        if(t&1){
            if(y-x==1)cout<<"2\n";
            else cout<<"1\n";
        }
        else{
            cout<<y-x<<"\n";
        }
        return;
    }
    if(t==1){
        cout<<calc(x,y)<<"\n";
        return;
    }
    if(t==3){
        cout<<"-1\n";
        return;
    }
    vector<ll>p,d(6,1e9);
    p={x,y,1,n,2,n-1};
    sort(p.begin(),p.end());
    p.resize(unique(p.begin(),p.end())-p.begin());
    priority_queue<pii,vector<pii>,greater<pii>>q;
    q.push({0,x});
    for(int i=0;i<p.size();i++){
        if(p[i]==x)d[i]=0;
    }
    while(!q.empty()){
        int now=q.top().second,to=0,dis=q.top().first;
        q.pop();
        int flag=0;
        for(int i=0;i<p.size();i++){
            if(p[i]==now&&d[i]<dis)flag=1;
        }
        if(flag)continue;
        for(int i=0;i<p.size();i++){
            if(d[i]>dis+1&&calc(p[i],now)>=k){
                d[i]=dis+1;
                
                q.push({d[i],p[i]});
            }
        }
    }
    for(int i=0;i<p.size();i++){
        //cout<<p[i]<<" "<<d[i]<<"\n";
        if(p[i]==y){
            if(d[i]==1e9)d[i]=-1;
            cout<<d[i]<<"\n";
            return;
        }
    }
    assert(0);
}
int main(){
    ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
    int t=1;
    cin>>t;
    while(t--)solve();
    return 0;
}

详细

Test #1:

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

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: -100
Wrong Answer
time: 0ms
memory: 3560kb

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
3
3
3
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

result:

wrong answer 3rd lines differ - expected: '-1', found: '3'