QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#358455#7866. TeleportationwdwTL 1ms3828kbC++201.5kb2024-03-19 19:57:582024-03-19 19:57:58

Judging History

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

  • [2024-03-19 19:57:58]
  • 评测
  • 测评结果:TL
  • 用时:1ms
  • 内存:3828kb
  • [2024-03-19 19:57:58]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef double db;
#define int long long
const int N=1e5+5;
const double eps=1e-10;
const int mod=1e9+7;
#define endl '\n'
struct node{
    int first,second;
    inline bool operator<(const node &x)const{
        return second>x.second;
    }
};
void solve() {
    int n,m;
    cin>>n>>m;
    vector<int>a(n+5),vis(n+5);
    for(int i=0;i<n;i++){
        cin>>a[i];
    }
    priority_queue<node>q;
    int ans=n+5;
    int cnt=1;
    q.push({0,0});
    while(!q.empty()){
        auto y=q.top();
        q.pop();
        if(vis[y.first])continue;
        vis[y.first]=1;
        if(y.second>=ans)continue;
        int p=a[y.first];
        if((y.first+p)%n>m){
            ans=min(ans,n-((y.first+p)%n)+m+1+y.second);
        }else{
            ans=min(ans,m-((y.first+p)%n)+1+y.second);
        }
        int l=1;
        if(cnt<=200*n) {
            while ((y.first + p) % n != y.first) {
                if((y.first + p) % n==m)continue;
                q.push({(y.first + p) % n, y.second + l});
                l++;
                p++;
                p %= n;
                if (y.second + l > ans)break;
                cnt++;
            }
        }
    }
    cout<<ans<<endl;
}
signed main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);cout.tie(nullptr);
    //cout<<fixed<<setprecision(12);
    int T=1;
    //  cin>>T;
    while(T--) solve();
    return 0;
}

详细

Test #1:

score: 100
Accepted
time: 1ms
memory: 3828kb

input:

4 3
0 1 2 3

output:

4

result:

ok 1 number(s): "4"

Test #2:

score: 0
Accepted
time: 0ms
memory: 3564kb

input:

4 3
0 0 0 0

output:

4

result:

ok 1 number(s): "4"

Test #3:

score: -100
Time Limit Exceeded

input:

4 3
2 2 2 2

output:


result: