QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#358455 | #7866. Teleportation | wdw | TL | 1ms | 3828kb | C++20 | 1.5kb | 2024-03-19 19:57:58 | 2024-03-19 19:57:58 |
Judging History
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;
}
Details
Tip: Click on the bar to expand more detailed information
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