QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#554031#9251. Graph Changingucup-team1134RE 0ms0kbC++232.7kb2024-09-09 02:20:112024-09-09 02:20:12

Judging History

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

  • [2024-09-09 02:20:12]
  • 评测
  • 测评结果:RE
  • 用时:0ms
  • 内存:0kb
  • [2024-09-09 02:20:11]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return true; } return false; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return true; } return false; }
#define vi vector<int>
#define vl vector<ll>
#define vii vector<pair<int,int>>
#define vll vector<pair<ll,ll>>
#define vvi vector<vector<int>>
#define vvl vector<vector<ll>>
#define vvii vector<vector<pair<int,int>>>
#define vvll vector<vector<pair<ll,ll>>>
#define vst vector<string>
#define pb push_back
#define all(x) (x).begin(),(x).end()
#define mkunique(x) sort(all(x));(x).erase(unique(all(x)),(x).end())
#define fi first
#define se second
#define mp make_pair
#define si(x) int(x.size())
const int mod=998244353,MAX=300005,INF=15<<26;

int gutyoku(int n,int k,int t,int x,int y){
    vvi E(n,vi(n,1)),dis(n,vi(n,INF));
    for(int i=0;i<n;i++){
        E[i][i]=0;
        
        for(int j=0;j<n;j++){
            if(i==j) dis[i][j]=0;
            else dis[i][j]=abs(i-j);
        }
    }
    
    cout<<"--- "<<n<<" "<<k<<" ---\n";
    
    for(int tt=1;tt<=t+1;tt++){
        if(tt-1==t){
            return dis[x][y];
        }
        vvi nE(n,vi(n,0)),ndis(n,vi(n,INF));
        for(int i=0;i<n;i++){
            ndis[i][i]=0;
            for(int j=0;j<n;j++){
                if(dis[i][j]!=INF&&dis[i][j]>=k){
                    nE[i][j]=1;
                    ndis[i][j]=1;
                }
            }
        }
        
        for(int z=0;z<n;z++) for(int x=0;x<n;x++) for(int y=0;y<n;y++) chmin(ndis[x][y],ndis[x][z]+ndis[z][y]);
        
        E=nE;
        dis=ndis;
    }
    
    return -1;
}

int solve(int n,int k,int t,int x,int y){
    if(x==y) return 0;
    if(n<=7){
        return gutyoku(n,k,t,x,y);
    }
    
    if(x>y) swap(x,y);
    
    if(t==0){
        return y-x;
    }
    
    if(k==1){
        return 1;
    }
    
    if(k==2){
        t%=2;
        if(t==0) return y-x;
        else{
            if(y-x==1) return 2;
            else return 1;
        }
    }
    
    if(t>=2) return INF;
    
    if(y-x>=k) return 1;
    
    if(n-1-x>=k&&n-1-y>=k) return 2;
    if(x>=k&&y>=k) return 2;
    
    if(n-1-x>=k&&n-1>=k&&y>=k) return 3;
    if(x>=k&&n-1>=k&&n-1-y>=k) return 3;
    
    return INF;
}
int main(){
    
    std::ifstream in("text.txt");
    std::cin.rdbuf(in.rdbuf());
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    int Q;cin>>Q;
    while(Q--){
        int n,k,t,x,y;cin>>n>>k>>t>>x>>y;x--;y--;
        int ans=solve(n,k,t,x,y);
        if(ans==INF) ans=-1;
        cout<<ans<<"\n";
    }
}


Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 0
Runtime Error

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:


result: