QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#625190 | #7866. Teleportation | noyapoyo | WA | 0ms | 3696kb | C++14 | 1.2kb | 2024-10-09 17:50:13 | 2024-10-09 17:50:13 |
Judging History
answer
#include <iostream>
#include <map>
#include <unordered_map>
#include <set>
using namespace std;
int n, x;
const int mxn = 1e5 + 5;
int arr[mxn];
set <int> v;
const int INF = 1e9;
int solve(int i, int j)
{
if (i == j)
{
v.insert(i * n + j);
return 0;
}
else
{
int idx_1 = ((i + arr[i] + 1) % n) * n + j;
int idx_2 = ((i + arr[i]) % n) * n + j;
int 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);
}
//int ans = INF;
int ans_3 = j - arr[i] + 1;
return min(min(ans_1, ans_3),ans_2);
}
}
int main()
{
cin >> n >> x;
for (int i = 0 ; i < n ; i++)
{
cin >> arr[i];
}
int 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: 3696kb
input:
4 3 0 1 2 3
output:
4
result:
ok 1 number(s): "4"
Test #2:
score: 0
Accepted
time: 0ms
memory: 3628kb
input:
4 3 0 0 0 0
output:
4
result:
ok 1 number(s): "4"
Test #3:
score: 0
Accepted
time: 0ms
memory: 3636kb
input:
4 3 2 2 2 2
output:
2
result:
ok 1 number(s): "2"
Test #4:
score: 0
Accepted
time: 0ms
memory: 3692kb
input:
2 1 0 0
output:
2
result:
ok 1 number(s): "2"
Test #5:
score: -100
Wrong Answer
time: 0ms
memory: 3696kb
input:
2 1 1 1
output:
0
result:
wrong answer 1st numbers differ - expected: '1', found: '0'