Submission details
Task:Wario Kart II
Sender:aalto26cw_001
Submission time:2026-09-16 17:49:56 +0300
Language:C++ (C++20)
Status:READY
Result:
Test results
testverdicttime
#1ACCEPTED0.00 sdetails
#2ACCEPTED0.00 sdetails
#3ACCEPTED0.00 sdetails
#4ACCEPTED0.00 sdetails
#5ACCEPTED0.00 sdetails
#6ACCEPTED0.00 sdetails
#7ACCEPTED0.00 sdetails
#8ACCEPTED0.00 sdetails
#9ACCEPTED0.00 sdetails
#10ACCEPTED0.00 sdetails
#11ACCEPTED0.00 sdetails
#12ACCEPTED0.00 sdetails
#13ACCEPTED0.00 sdetails
#14ACCEPTED0.00 sdetails
#15ACCEPTED0.00 sdetails
#16ACCEPTED0.00 sdetails
#17ACCEPTED0.00 sdetails
#18ACCEPTED0.00 sdetails
#19ACCEPTED0.00 sdetails
#20ACCEPTED0.00 sdetails
#21ACCEPTED0.00 sdetails
#22ACCEPTED0.00 sdetails
#23ACCEPTED0.00 sdetails
#24ACCEPTED0.00 sdetails
#25ACCEPTED0.00 sdetails
#26ACCEPTED0.00 sdetails
#27ACCEPTED0.00 sdetails
#28ACCEPTED0.00 sdetails
#29ACCEPTED0.00 sdetails
#30ACCEPTED0.00 sdetails
#31ACCEPTED0.00 sdetails
#32ACCEPTED0.00 sdetails
#33ACCEPTED0.00 sdetails
#34ACCEPTED0.00 sdetails
#35ACCEPTED0.00 sdetails
#36ACCEPTED0.00 sdetails
#37ACCEPTED0.00 sdetails
#38ACCEPTED0.00 sdetails
#39ACCEPTED0.00 sdetails
#40ACCEPTED0.00 sdetails
#41ACCEPTED0.00 sdetails
#42ACCEPTED0.00 sdetails
#43ACCEPTED0.00 sdetails
#44ACCEPTED0.00 sdetails
#45ACCEPTED0.00 sdetails
#46ACCEPTED0.00 sdetails
#47ACCEPTED0.00 sdetails
#48ACCEPTED0.00 sdetails
#49ACCEPTED0.01 sdetails
#50ACCEPTED0.06 sdetails
#51ACCEPTED0.06 sdetails
#52ACCEPTED0.06 sdetails
#53ACCEPTED0.06 sdetails
#54ACCEPTED0.06 sdetails
#55ACCEPTED0.05 sdetails
#56ACCEPTED0.06 sdetails
#57ACCEPTED0.05 sdetails
#58ACCEPTED0.06 sdetails
#590.05 sdetails

Code

#include <iostream>
#include <vector>
#include <functional>
#include <set>
#include <algorithm>
#include <stack>
#include <unordered_map>

std::tuple<int> readInt1(){
    int a;
    std::cin >> a;
    return {a};
}
std::tuple<int,int> readInt2(){
    int a, b;
    std::cin >> a >> b;
    return {a,b};
}
std::tuple<int,int,int> readInt3(){
    int a, b, c;
    std::cin >> a >> b >> c;
    return {a,b,c};
}

std::vector<int> readVecInt(int n){
    std::vector<int> arr(n);
    for (int i = 0; i < n; i++){
        int a;
        std::cin >> a;
        arr[i] = a;
    }
    return arr;
}

std::vector<long long> readVecLong(int n){
    std::vector<long long> arr(n);
    for (int i = 0; i < n; i++){
        long long a;
        std::cin >> a;
        arr[i] = a;
    }
    return arr;
}

std::vector<std::tuple<int,int>> readVecTup2(int n){
    std::vector<std::tuple<int,int>> arr(n);
    for (int i = 0; i < n; i++){
        int a, b;
        std::cin >> a;
        std::cin >> b;
        arr[i] = {a,b};
    }
    return arr;
}

std::vector<std::tuple<int,int,int>> readVecTup3(int n){
    std::vector<std::tuple<int,int,int>> arr(n);
    for (int i = 0; i < n; i++){
        int a, b, c;
        std::cin >> a;
        std::cin >> b;
        std::cin >> c;
        arr[i] = {a,b,c};
    }
    return arr;
}

void printNewLine(){std::cout << "\n";}
template<typename T, typename... Ts>
std::tuple<Ts...> tail(std::tuple<T,Ts...> as){
    return std::apply([](T &a, Ts... b){return std::make_tuple(b...);},as);
}

template<typename T>
void print(T a){std::cout << a;}

template<typename T, typename Ts>
void print(std::tuple<T,Ts> a){
    print(std::get<0>(a));
    print(" ");
    print(std::get<1>(a));
}

template<typename T, typename... Ts>
void print(std::tuple<T,Ts...> a){
    print(std::get<0>(a));
    print(" ");
    print(tail(a));
}
template<typename T>
void println(T a){print(a);printNewLine();}

template<typename T>
void printVec(const std::vector<T> &arr, int width = -1){
    if (width == -1) width = arr.size();
    for (int i = 0; i < (int)arr.size(); i++){
        if ((i%width) == width-1){
            print(" ");
            println(arr[i]);
        }else if ((i%width) == 0){        
            print(arr[i]);
        }else {
            print(" ");
            print(arr[i]);
        }
    }    
}


template<typename T>
void sorted(std::vector<T> &arr){
    std::sort(arr.begin(),arr.end(),[](const T &a, const T &b){ return a < b; });
}


template<typename T>
std::set<T> toSet(const std::vector<T> &vec){
    std::set<T> c;
    for (T a : vec){ c.emplace(a);}
    return c;
}

template<typename T, typename N>
std::vector<N> map(const std::vector<T> &a, const std::function<N(T)> &transform){
    std::vector<N> b(a.size());
    int i = 0;
    for (T x : a){
        b[i] = transform(x);
        i++;
    }
    return b;
}

template<typename N, typename M, typename R>
std::vector<R> zip(const std::vector<N> &a, const  std::vector<M> &b, const std::function<R(N,M)> &transform){
    int n = std::min(a.size(),b.size());
    std::vector<R> res(n);
    for (int i = 0; i < n; i++){
        res[i] = transform(a[i],b[i]);
    }
    return res;
}

template<typename T, typename N>
std::vector<N> convertVec(const std::vector<T> &a){
    std::vector<N> b(a.size());
    int i = 0;
    for (T x : a){
        b[i] = x;
        i++;
    }
    return b;
}

template<typename T, typename R>
R reduce(const std::vector<T> &arr, R init, const std::function<R(const R,const T)> &transform){
    R current = init;
    for (int idx = 0; idx < (int)arr.size(); idx++){
        current = transform(current,arr[idx]);
    };
    return current;
}
template<typename T>
T max(const std::vector<T> &arr){return reduce(arr, arr[0], static_cast<std::function<T(const T,const T)>>(static_cast<const T& (*)(const T&, const T&)>(std::max<T>)));}
template<typename T>
T min(const std::vector<T> &arr){return reduce(arr, arr[0], static_cast<std::function<T(const T,const T)>>(static_cast<const T& (*)(const T&, const T&)>(std::min<T>)));}

template<typename T>
std::function<T(const T,const T)> add(){return [](T a,T b){return a+b;};}
template<typename T>
std::function<T(const T,const T)> modAdd(T mod){return [mod](T a,T b){return (((a+b)%mod)+mod)%mod;};}
template<typename T, typename R>
std::function<R(const R,const T)> mulAdd(R mul){return [mul](R a,T b){return a+b*mul;};}
template<typename T>
T sum(const std::vector<T> &arr){return reduce(arr, 0, add<T>());}
template<typename T>
T avg(const std::vector<T> &arr){return reduce(arr, 0.0, mulAdd<double,T>(1.0/arr.size()));}

template<typename T>
T binarySearch(T min, T max, const std::function<bool(T)> &leq){
    if (min == max) return max;
    T guess = (min+max)/2;
    if (leq(guess)){
        return binarySearch(min,guess,leq);
    }else{
        return binarySearch(guess+1,max,leq);
    }
}

template<typename T>
T binarySearchDecending(T min, T max, const std::function<bool(T)> &leq){
    std::function<bool(T)> gt = [leq](T x){
        return !leq(x);
    };
    return binarySearch(min,max+1, gt)-1;
}

template<typename T>
std::vector<T> cloneVec(std::vector<T> a){return a;}

template<typename T>
std::vector<T> padding(const std::vector<T> &initial, T num, int start, int end){
    std::vector<T> arr(start+initial.size()+end);
    for (int i = 0; i < start; i++){
        arr[i] = num;
    }
    for (int i = 0; i < (int)initial.size(); i++){
        arr[start+i] = initial[i];
    }
    for (int i = 0; i < end; i++){
        arr[start+initial.size()+i] = num;
    }
    return arr;
}

template<typename T>
int findMax(int start, int end, const std::function<T(int)> &maxHeuristic){
    T initialGuess = maxHeuristic(start);
    int index = start;
    for (int i = start; i <= end; i++){
        if (initialGuess < maxHeuristic(i)){
            initialGuess = maxHeuristic(i);
            index = i;
        }
    }
    return index;
}

template<typename T>
void operateOnMax(int start, int end, const std::function<T(int)> &maxHeuristic, const std::function<void(int)> &found){
    found(findMax(start,end,maxHeuristic));
}

template<typename T>
void stackOperate(T init, const std::function<std::vector<T>(T)> operate){
    std::stack<T> stack;
    stack.push(init);
    while (!stack.empty()){
        T next = stack.top();
        stack.pop();
        std::vector<T> nextSteps = operate(next);
        for (T a : nextSteps){
            stack.push(a);
        }
    }
}

template<typename T>
void recursiveVectorSplit(int start, int end, int distl, int distr, const std::function<T(int)> &maxHeuristic, const std::function<void(int)> &found){
    if (start == end){
        return found(start);
    }else if (end < start){
        return;
    }
    std::tuple<int,int> range = {start,end};
    std::function<std::vector<std::tuple<int,int>>(std::tuple<int,int>)> splitter = [distl, distr,&maxHeuristic,&found](std::tuple<int,int> range){
        auto [start,end] = range;
        int idx = findMax(start, end, maxHeuristic);
        found(idx);
        std::vector<std::tuple<int,int>> next;
        if (idx+distl+1 <= end){
            next.push_back({idx+distl+1,end});
        }
        if (start <= idx-distr-1){
            next.push_back({start, idx-distr-1});
        }
        return next;
    };
    stackOperate(range,splitter);
}


template<typename T>
std::vector<T> dynamicallyComputableList(int n, std::function<T(std::vector<T>&,int)> next){
    std::vector<T> arr(n);
    for (int i = 0; i < n; i++){
        arr[i] = next(arr,i);
    }
    return arr;
}
template<typename T>
int indexOfBinarySearch(const std::vector<T> &arr, const T &find){
    return binarySearch(0,(int)arr.size()-1,(std::function<bool(int)>)[&arr, &find](int guess){return find <= arr[guess];});
}

template<typename T>
std::unordered_map<T, int> indexCompress(const std::vector<T> &arr){
    std::unordered_map<T, int> compressed;
    int i = 0;
    for (T x : arr){
        if (compressed.find(x) != compressed.end()) compressed[x] = i++;
    }
    return compressed;
}   
#include <limits>
template<typename T>
std::tuple<T, std::vector<int>> shortestPathDirected(const std::vector<std::tuple<int, int, T>> &edgesMessy, int start, int goal){
    //assumes all are between 0 <= n < c*(number of vertexies), where c is reasonably small constant.  
    std::vector<int> vertexies = {};
    for (auto& [s,g,c] : edgesMessy){
        vertexies.push_back(s);
        vertexies.push_back(g);
    }
    //std::unordered_map<int, int> mapping = indexCompress(vertexies);
    //println("Start");
    //std::set<int> setVertexies = {start,goal};
    //for (auto [s,g,c] : edgesMessy){
    //    setVertexies.emplace(s);
    //    setVertexies.emplace(g);
    //}
    //std::vector<int> vertexies;
    //for (int v : setVertexies){
    //    vertexies.push_back(v);
    //}
    //sorted(vertexies);
    //println("end2");
    std::vector<std::tuple<int, int, T>> edges = edgesMessy;
    //for (auto& [s,g,c] : edges){
    //    s = indexOfBinarySearch(vertexies,s);
    //    g = indexOfBinarySearch(vertexies,g);
    //}
    int mappedStart = start;//indexOfBinarySearch(vertexies,start);
    int mappedEnd   = goal;//indexOfBinarySearch(vertexies,goal);
    //println("end1");
    int n = max(vertexies)+1;
    std::vector<T> distance(n);
    for (int i = 0; i < n; i++) distance[i] = std::numeric_limits<T>::max()/4;//(T)4611686018427387903L;
    distance[mappedStart] = 0;
    for (int i = 1; i <= n; i++) {
        bool changed = false;
        for (auto e : edges) {
            auto [a, b, w] = e;
            if (!changed) {changed = (distance[b] != std::min(distance[b], distance[a]+w));}
            distance[b] = std::min(distance[b], distance[a]+w);
        }
        if (!changed) break;
        if (changed && i == n){
            //handle inifnite loop
        }
    }
    //println("end2");
    return std::tuple(distance[mappedEnd],(std::vector<int>){});
}


struct Num{

};


void marioKart2(){
    auto [n,k] = readInt2();
    auto arr = readVecLong(n);
    int start = 0;
    int goal = n;
    std::vector<std::tuple<int, int, long long>> edges;
    for (int i = 0; i < n; i++){
        std::tuple<int,int,long long> a = {i, i+1,10000};
        edges.push_back(a);
        if (i+arr[i]+k <= n){
            std::tuple<int,int,long long> b = {i, i+(arr[i])+k,10000*((double)(k+1))}; //(1+arr[i])*(1.0/(1+arr[i]+k)
            edges.push_back(b);
        }else if (i+arr[i] <= n){
            int dist = n-(i+(arr[i]));
            std::tuple<int,int,long long> b = {i, n, 10000*(double)(dist+1)}; //(1+arr[i])*(1.0/(1+arr[i]+k)
            edges.push_back(b);
        } else {
            int dist = n-i;
            std::tuple<int,int,long long> b = {i, n, 10000*((double)dist)/(arr[i])}; //(1+arr[i])*(1.0/(1+arr[i]+k)
            edges.push_back(b);
        }
    }
    //printVec(edges,1);
    auto [min,path] = shortestPathDirected(edges,start,goal);
    println(min*(1.0/10000));
}




template<typename T>
std::vector<T> distanceTable(const std::vector<T> &init, const  std::function<T(T,T)> &distance){
    int n = init.size();
    std::vector<T> table(n*n);
    for (int i = 0; i < n; i++){
        table[i+n*i] = init[i];
        for (int j = i-1; j >= 0; j--){
            table[j+n*i] = distance(init[j],table[j+1+n*i]);
        }
        for (int j = i+1; j < n; j++){
            table[j+n*i] = distance(table[j-1+n*i],init[j]);
        }
    }
    return table;
}

void particles(){
    auto [n] = readInt1();
    auto arr = readVecLong(n);
    std::vector<long long> table = distanceTable(arr,add<long long>());
    printVec(table,n);
    //println(cost[n*n-1]);
}


int main() {
    marioKart2();
    //particles();
    return 0;
}

Test details

Test 1

Verdict: ACCEPTED

input
1 5
3 

correct output
0.33333333333333333334

user output
0.3333

Test 2

Verdict: ACCEPTED

input
2 5
3 4 

correct output
0.66666666666666666668

user output
0.6666

Test 3

Verdict: ACCEPTED

input
2 5
2 2 

correct output
1.00000000000000000000

user output
1

Test 4

Verdict: ACCEPTED

input
3 5
2 2 2 

correct output
2.00000000000000000000

user output
2

Test 5

Verdict: ACCEPTED

input
3 5
3 4 3 

correct output
1.00000000000000000000

user output
1

Test 6

Verdict: ACCEPTED

input
3 5
2 2 2 

correct output
2.00000000000000000000

user output
2

Test 7

Verdict: ACCEPTED

input
4 5
3 4 3 4 

correct output
1.75000000000000000000

user output
1.75

Test 8

Verdict: ACCEPTED

input
4 5
2 2 2 4 

correct output
3.00000000000000000000

user output
3

Test 9

Verdict: ACCEPTED

input
4 3
2 2 2 2 

correct output
3.00000000000000000000

user output
3

Test 10

Verdict: ACCEPTED

input
5 5
3 4 3 4 3 

correct output
2.00000000000000000000

user output
2

Test 11

Verdict: ACCEPTED

input
5 5
2 2 2 4 2 

correct output
3.50000000000000000000

user output
3.5

Test 12

Verdict: ACCEPTED

input
5 5
2 2 2 2 2 

correct output
4.00000000000000000000

user output
4

Test 13

Verdict: ACCEPTED

input
5 5
2 2 3 3 4 

correct output
3.00000000000000000000

user output
3

Test 14

Verdict: ACCEPTED

input
5 1
4 4 4 3 4 

correct output
2.00000000000000000000

user output
2

Test 15

Verdict: ACCEPTED

input
5 4
2 3 5 5 3 

correct output
2.59999999999999999991

user output
2.6

Test 16

Verdict: ACCEPTED

input
5 1
3 2 2 2 2 

correct output
2.50000000000000000000

user output
2.5

Test 17

Verdict: ACCEPTED

input
5 1
3 5 4 3 5 

correct output
1.79999999999999999996

user output
1.8

Test 18

Verdict: ACCEPTED

input
5 1
5 3 4 5 2 

correct output
1.00000000000000000000

user output
1

Test 19

Verdict: ACCEPTED

input
5 2
3 2 2 2 2 

correct output
3.00000000000000000000

user output
3

Test 20

Verdict: ACCEPTED

input
10 5
3 4 3 4 3 3 3 3 3 2 

correct output
6.66666666666666666652

user output
6.6666

Test 21

Verdict: ACCEPTED

input
10 5
2 2 2 4 2 2 2 3 2 3 

correct output
7.00000000000000000000

user output
7

Test 22

Verdict: ACCEPTED

input
10 5
2 2 2 2 2 2 2 2 2 2 

correct output
8.00000000000000000000

user output
8

Test 23

Verdict: ACCEPTED

input
10 5
2 2 3 3 4 3 4 2 2 2 

correct output
7.00000000000000000000

user output
7

Test 24

Verdict: ACCEPTED

input
10 1
4 4 4 3 4 3 2 2 4 2 

correct output
4.50000000000000000000

user output
4.5

Test 25

Verdict: ACCEPTED

input
10 4
2 3 5 5 3 2 4 3 5 3 

correct output
6.00000000000000000000

user output
6

Test 26

Verdict: ACCEPTED

input
10 1
3 2 2 2 2 3 3 2 3 3 

correct output
5.33333333333333333348

user output
5.3333

Test 27

Verdict: ACCEPTED

input
10 1
3 5 4 3 5 3 4 3 4 2 

correct output
4.00000000000000000000

user output
4

Test 28

Verdict: ACCEPTED

input
10 1
5 3 4 5 2 3 2 4 3 5 

correct output
3.75000000000000000000

user output
3.75

Test 29

Verdict: ACCEPTED

input
10 2
3 2 2 2 2 2 2 4 3 2 

correct output
5.75000000000000000000

user output
5.75

Test 30

Verdict: ACCEPTED

input
100 72
51 37 52 34 51 26 38 40 24 27 ...

correct output
42.00000000000000000000

user output
42

Test 31

Verdict: ACCEPTED

input
100 72
94 2 14 31 100 16 25 11 41 20 ...

correct output
4.96000000000000000003

user output
4.96

Test 32

Verdict: ACCEPTED

input
100 2
19 12 20 10 11 9 8 8 4 5 15 13...

correct output
18.70588235294117647120

user output
18.7058

Test 33

Verdict: ACCEPTED

input
100 71
8 4 2 6 6 9 5 9 2 3 2 3 3 2 2 ...

correct output
85.00000000000000000000

user output
85

Test 34

Verdict: ACCEPTED

input
100 55
17 89 79 66 56 64 55 21 14 89 ...

correct output
12.00000000000000000000

user output
12

Test 35

Verdict: ACCEPTED

input
100 87
6 3 4 7 7 4 2 5 4 6 4 5 4 3 7 ...

correct output
90.00000000000000000000

user output
90

Test 36

Verdict: ACCEPTED

input
100 33
21 79 8 5 36 12 94 57 11 51 59...

correct output
7.00000000000000000000

user output
7

Test 37

Verdict: ACCEPTED

input
100 78
9 12 24 18 12 24 9 14 8 13 3 3...

correct output
77.00000000000000000000

user output
77

Test 38

Verdict: ACCEPTED

input
100 97
2 3 2 3 3 2 2 2 3 2 3 2 2 3 3 ...

correct output
98.00000000000000000000

user output
98

Test 39

Verdict: ACCEPTED

input
100 50
20 20 2 6 13 7 2 10 34 17 7 11...

correct output
52.96666666666666666713

user output
52.9666

Test 40

Verdict: ACCEPTED

input
200 72
51 37 52 34 51 26 38 40 24 27 ...

correct output
89.00000000000000000000

user output
89

Test 41

Verdict: ACCEPTED

input
200 72
94 2 14 31 100 16 25 11 41 20 ...

correct output
73.91891891891891892136

user output
73.9189

Test 42

Verdict: ACCEPTED

input
200 2
19 12 20 10 11 9 8 8 4 5 15 13...

correct output
36.90000000000000000139

user output
36.9

Test 43

Verdict: ACCEPTED

input
200 71
8 4 2 6 6 9 5 9 2 3 2 3 3 2 2 ...

correct output
177.00000000000000000000

user output
177

Test 44

Verdict: ACCEPTED

input
200 55
17 89 79 66 56 64 55 21 14 89 ...

correct output
58.62790697674418604821

user output
58.6279

Test 45

Verdict: ACCEPTED

input
200 87
6 3 4 7 7 4 2 5 4 6 4 5 4 3 7 ...

correct output
184.00000000000000000000

user output
184

Test 46

Verdict: ACCEPTED

input
200 33
21 79 8 5 36 12 94 57 11 51 59...

correct output
39.97647058823529411797

user output
39.9764

Test 47

Verdict: ACCEPTED

input
1000 78
9 12 24 18 12 24 9 14 8 13 3 3...

correct output
778.00000000000000000000

user output
778

Test 48

Verdict: ACCEPTED

input
1000 97
2 3 2 3 3 2 2 2 3 2 3 2 2 3 3 ...

correct output
980.00000000000000000000

user output
980

Test 49

Verdict: ACCEPTED

input
10000 50
20 20 2 6 13 7 2 10 34 17 7 11...

correct output
6049.00000000000000000000

user output
6049

Test 50

Verdict: ACCEPTED

input
100000 59
39252 46336 33082 47087 29905 ...

correct output
64.97006295772838237179

user output
64.97

Test 51

Verdict: ACCEPTED

input
100000 100
30041 38891 6 5345 12609 41664...

correct output
203.77740406665647454609

user output
203.777

Test 52

Verdict: ACCEPTED

input
100000 18
1132 40617 23967 41323 18982 2...

correct output
40.94677609727978918885

user output
40.9467

Test 53

Verdict: ACCEPTED

input
100000 7
39007 46266 16025 6684 28138 3...

correct output
14.93255621844882973827

user output
14.9325

Test 54

Verdict: ACCEPTED

input
100000 90
52921 16702 94063 82743 69126 ...

correct output
91.66979787325027796002

user output
91.6697

Test 55

Verdict: ACCEPTED

input
100000 5
19332 18457 4591 8077 20395 21...

correct output
35.88927530302255408320

user output
35.8892

Test 56

Verdict: ACCEPTED

input
100000 95
29643 18699 73326 5739 3724 33...

correct output
96.91999685748703713406

user output
96.9199

Test 57

Verdict: ACCEPTED

input
100000 22
5953 2436 3347 7466 5522 3478 ...

correct output
330.93907248742010063225

user output
330.939

Test 58

Verdict: ACCEPTED

input
100000 1
84598 20915 75920 32975 46369 ...

correct output
2.81955087271179225200

user output
2.8195

Test 59

Verdict:

input
100000 36
522 520 516 9 140 330 149 15 2...

correct output
3870.97771317829457360382

user output
3870.98