QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#682335#7866. TeleportationinfCraftWA 1ms3984kbC++171.5kb2024-10-27 15:02:062024-10-27 15:02:06

Judging History

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

  • [2024-10-27 15:02:06]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:3984kb
  • [2024-10-27 15:02:06]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;
#define endl '\n'
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define pb push_back

#define Yes cout << "Yes\n"
#define No cout << "No\n"
#define YES cout << "YES\n"
#define NO cout << "NO\n"
#define ff first
#define ss second
#define fori(x,y) for(int i=x;i<=(int)(y);++i)
#define forj(x,y) for(int j=x;j<=(int)(y);++j)
#define fork(x,y) for(int k=x;k<=(int)(y);++k)

#define debug(x) cerr << #x << " = " << x << endl

typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;

ll MOD = 998244353;
ll qpow(ll a,ll p) {ll res=1; while(p) {if (p&1) {res=res*a%MOD;} a=a*a%MOD; p>>=1;} return res;}

const int N = 2e5+7;

int arr[N];
bool vis[N];
signed main() {
	IOS;
    int n, x;
    cin >> n >> x;
    fori(0, n-1) cin >> arr[i];
    
    int ans = n;
    priority_queue<pii,vector<pii>,greater<pii>> pri;
    pri.push({0, 0});
    while (pri.size()) {
        auto pi = pri.top();
        pri.pop();
        int u = pi.second;
        if (vis[u]) continue;
        vis[u] = true;
        if (u == x) {
            ans = pi.first;
            break;
        }
        int p = arr[u];
        int cnt = 0;
        while (1) {
            cnt++;
            pri.push({pi.first+cnt, p});
            // if (p == x) {
            //     ans = min(ans, pi.first+cnt);
            // }
            if (pi.first+cnt>ans) break;
            p = (p+1)%n;
        }
    }
    cout << ans << endl;
	return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

input:

4 3
0 1 2 3

output:

4

result:

ok 1 number(s): "4"

Test #2:

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

input:

4 3
0 0 0 0

output:

4

result:

ok 1 number(s): "4"

Test #3:

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

input:

4 3
2 2 2 2

output:

2

result:

ok 1 number(s): "2"

Test #4:

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

input:

2 1
0 0

output:

2

result:

ok 1 number(s): "2"

Test #5:

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

input:

2 1
1 1

output:

1

result:

ok 1 number(s): "1"

Test #6:

score: -100
Wrong Answer
time: 1ms
memory: 3984kb

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:

6

result:

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