QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#596114 | #7866. Teleportation | 000226 | WA | 2ms | 9720kb | C++17 | 1.2kb | 2024-09-28 15:09:24 | 2024-09-28 15:09:28 |
Judging History
answer
#include <bits/stdc++.h>
#define int long long
using namespace std;
using i128 = __int128;
#define lep(i, l, r) for(int i = (l); i <= (r); i ++)
#define rep(i, l, r) for(int i = (l); i >= (r); i --)
#define Lep(i, l, r) for(int i = (l); i < (r); i ++)
#define debug(...) fprintf (stderr, __VA_ARGS__)
using i64 = long long;
using ld = long double;
using ui64 = unsigned long long;
const int N = 2e5 + 5;
int n, x;
int a[N];
vector<int> e[N];
void solve() {
cin >> n >> x;
lep (i, 0, n - 1) cin >> a[i];
lep (i, 1, n - 1) {
int to = i + a[i];
to = to % n;
e[i].push_back(to);
}
e[0].push_back(n), e[n].push_back((a[0] + 1) % n);
lep (i, 1, n - 1) {
int to = i + 1;
if (to == n) to = 0;
e[i].push_back(to);
}
vector<int> dis(n + 1, -1);
queue<int> q;
q.push(0);
dis[0] = 0;
while (!q.empty()) {
int u = q.front(); q.pop();
for (int v : e[u]) {
if (dis[v] == -1) {
dis[v] = dis[u] + 1;
q.push(v);
}
}
}
if (dis[x] == -1) cout << -1 << endl;
else cout << dis[x] << endl;
}
signed main() {
ios :: sync_with_stdio(false);
cin.tie(0); cout.tie(0);
int Case = 1;;
//cin >> Case;
while (Case --) solve();
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 2ms
memory: 8996kb
input:
4 3 0 1 2 3
output:
4
result:
ok 1 number(s): "4"
Test #2:
score: 0
Accepted
time: 0ms
memory: 9436kb
input:
4 3 0 0 0 0
output:
4
result:
ok 1 number(s): "4"
Test #3:
score: 0
Accepted
time: 2ms
memory: 9640kb
input:
4 3 2 2 2 2
output:
2
result:
ok 1 number(s): "2"
Test #4:
score: 0
Accepted
time: 0ms
memory: 8752kb
input:
2 1 0 0
output:
2
result:
ok 1 number(s): "2"
Test #5:
score: -100
Wrong Answer
time: 1ms
memory: 9720kb
input:
2 1 1 1
output:
-1
result:
wrong answer 1st numbers differ - expected: '1', found: '-1'