QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#358625#7866. TeleportationAlbert711WA 0ms3620kbC++201.4kb2024-03-19 21:39:272024-03-19 21:39:27

Judging History

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

  • [2024-03-19 21:39:27]
  • 评测
  • 测评结果:WA
  • 用时:0ms
  • 内存:3620kb
  • [2024-03-19 21:39:27]
  • 提交

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'

int n,m;

struct node{
    int first,second;
    inline bool operator<(const node &x)const{
        return second>x.second;
    }
};

inline int mo(int a,int b){
    return (a+b)>=n?a+b-n:a+b;
}
void solve() {
    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+1;
    q.push({0,0});
    while(!q.empty()) {
        auto y = q.top();
        q.pop();
        if (y.second >= ans)continue;
        if(vis[y.first])continue;
        vis[y.first]=1;
        int p = a[y.first];
        if (mo(y.first , p) > m) {
            ans = min(ans, n - (mo(y.first , p)) + m + 1 + y.second);
        } else {
            ans = min(ans, m - (mo(y.first , p)) + 1 + y.second);
        }
        int l = 1;
        while (mo(y.first , p)  !=m) {
            l++;
            if (y.second + l > ans) break;
            if(vis[mo(y.first , p)]==0) q.push({mo(y.first , p) , y.second + l});
            p=mo(p,1);
        }
    }
    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: 0ms
memory: 3620kb

input:

4 3
0 1 2 3

output:

4

result:

ok 1 number(s): "4"

Test #2:

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

input:

4 3
0 0 0 0

output:

4

result:

ok 1 number(s): "4"

Test #3:

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

input:

4 3
2 2 2 2

output:

2

result:

ok 1 number(s): "2"

Test #4:

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

input:

2 1
0 0

output:

2

result:

ok 1 number(s): "2"

Test #5:

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

input:

2 1
1 1

output:

1

result:

ok 1 number(s): "1"

Test #6:

score: -100
Wrong Answer
time: 0ms
memory: 3612kb

input:

300 25
182 9 13 211 258 132 27 42 218 200 271 258 164 121 8 84 29 195 141 290 110 0 272 93 142 134 140 32 232 99 162 199 297 287 212 29 182 53 61 98 116 282 75 245 230 165 22 4 179 89 274 231 46 299 248 208 200 285 221 50 221 199 294 241 195 138 22 204 113 100 132 276 158 146 238 178 100 94 131 157 ...

output:

14

result:

wrong answer 1st numbers differ - expected: '10', found: '14'