117862024-11-10 18:36:12AGergoLudak Harcacpp17Accepted 100/10012ms1588 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) << " ";
    }
}
SubtaskSumTestVerdictTimeMemory
subtask10/0
1Accepted1ms320 KiB
2Accepted1ms320 KiB
subtask225/25
3Accepted1ms320 KiB
4Accepted1ms320 KiB
5Accepted1ms320 KiB
6Accepted2ms320 KiB
7Accepted8ms1284 KiB
subtask340/40
8Accepted1ms320 KiB
9Accepted2ms320 KiB
10Accepted2ms320 KiB
11Accepted3ms580 KiB
12Accepted4ms716 KiB
13Accepted8ms1080 KiB
14Accepted9ms1392 KiB
15Accepted12ms1468 KiB
subtask435/35
16Accepted3ms568 KiB
17Accepted3ms440 KiB
18Accepted4ms568 KiB
19Accepted6ms824 KiB
20Accepted6ms824 KiB
21Accepted7ms1080 KiB
22Accepted8ms1080 KiB
23Accepted8ms1336 KiB
24Accepted10ms1396 KiB
25Accepted12ms1588 KiB