11786 | 2024-11-10 18:36:12 | AGergo | Ludak Harca | cpp17 | Accepted 100/100 | 12ms | 1588 KiB |
#include <bits/stdc++.h>
using namespace std;
int n;
vector<int> j;
vector<int> whereTo;
int run(int spot, int dice, int step)
{
step++;
spot=spot+dice;
if(spot > n-1)
{
return(step);
}
else if(whereTo[spot]>n-1)
{
return(step);
}
else
{
return(run(whereTo[spot],dice,step));
}
}
int main()
{
cin.tie(0);
iostream::sync_with_stdio(0);
cin >> n;
j = vector<int>(n,0);
for(int i = 0; i<n ;i++)
{
cin >> j[i];
}
whereTo = vector<int>(n);
for(int i = n-1; i >= 0;i--)
{
if(j[i] == 0)
{
whereTo[i] = i;
}
else if(i+j[i] > n-1)
{
whereTo[i] = i+j[i];
}
else
{
whereTo[i] = whereTo[i+j[i]];
}
}
for(int i = 1; i<7; i++)
{
cout << run(0,i,0) << " ";
}
}
Subtask | Sum | Test | Verdict | Time | Memory | ||
---|---|---|---|---|---|---|---|
subtask1 | 0/0 | ||||||
1 | Accepted | 1ms | 320 KiB | ||||
2 | Accepted | 1ms | 320 KiB | ||||
subtask2 | 25/25 | ||||||
3 | Accepted | 1ms | 320 KiB | ||||
4 | Accepted | 1ms | 320 KiB | ||||
5 | Accepted | 1ms | 320 KiB | ||||
6 | Accepted | 2ms | 320 KiB | ||||
7 | Accepted | 8ms | 1284 KiB | ||||
subtask3 | 40/40 | ||||||
8 | Accepted | 1ms | 320 KiB | ||||
9 | Accepted | 2ms | 320 KiB | ||||
10 | Accepted | 2ms | 320 KiB | ||||
11 | Accepted | 3ms | 580 KiB | ||||
12 | Accepted | 4ms | 716 KiB | ||||
13 | Accepted | 8ms | 1080 KiB | ||||
14 | Accepted | 9ms | 1392 KiB | ||||
15 | Accepted | 12ms | 1468 KiB | ||||
subtask4 | 35/35 | ||||||
16 | Accepted | 3ms | 568 KiB | ||||
17 | Accepted | 3ms | 440 KiB | ||||
18 | Accepted | 4ms | 568 KiB | ||||
19 | Accepted | 6ms | 824 KiB | ||||
20 | Accepted | 6ms | 824 KiB | ||||
21 | Accepted | 7ms | 1080 KiB | ||||
22 | Accepted | 8ms | 1080 KiB | ||||
23 | Accepted | 8ms | 1336 KiB | ||||
24 | Accepted | 10ms | 1396 KiB | ||||
25 | Accepted | 12ms | 1588 KiB |