QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#625213 | #7866. Teleportation | noyapoyo | WA | 0ms | 3692kb | C++14 | 1.2kb | 2024-10-09 17:57:28 | 2024-10-09 17:57:28 |
Judging History
answer
#include <iostream>
#include <map>
#include <unordered_map>
#include <set>
#define ll long long
using namespace std;
ll n, x;
const ll mxn = 1e5 + 5;
ll arr[mxn];
set <ll> v;
const ll INF = 1e9;
ll solve(ll i, ll j)
{
if (i == j)
{
v.insert(i * n + j);
return 0;
}
else
{
ll idx_1 = ((i + arr[i] + 1) % n) * n + j;
ll idx_2 = ((i + arr[i]) % n) * n + j;
ll ans_1, ans_2;
v.insert(i * n + j);
if (v.find(idx_1) == v.end())
{
ans_1 = solve((i + arr[i] + 1) % n, j) + 2;
}
else
{
ans_1 = INF;
//v.insert(idx_1);
}
if (v.find(idx_2) == v.end())
{
ans_2 = solve((i + arr[i]) % n, j);
}
else
{
ans_2 = INF;
//v.insert(idx_2);
}
//ll ans = INF;
ll ans_3 = j - arr[i] + 1;
return min(min(ans_1, ans_3),ans_2);
}
}
int main()
{
cin >> n >> x;
for (ll i = 0 ; i < n ; i++)
{
cin >> arr[i];
}
ll ans = 0;
ans = solve(0, x);
cout << ans << "\n";
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 3692kb
input:
4 3 0 1 2 3
output:
4
result:
ok 1 number(s): "4"
Test #2:
score: 0
Accepted
time: 0ms
memory: 3592kb
input:
4 3 0 0 0 0
output:
4
result:
ok 1 number(s): "4"
Test #3:
score: 0
Accepted
time: 0ms
memory: 3644kb
input:
4 3 2 2 2 2
output:
2
result:
ok 1 number(s): "2"
Test #4:
score: 0
Accepted
time: 0ms
memory: 3628kb
input:
2 1 0 0
output:
2
result:
ok 1 number(s): "2"
Test #5:
score: -100
Wrong Answer
time: 0ms
memory: 3576kb
input:
2 1 1 1
output:
0
result:
wrong answer 1st numbers differ - expected: '1', found: '0'