Submission #92009

# Submission time Handle Problem Language Result Execution time Memory
92009 2019-01-01T01:52:15 Z easrui Race (IOI11_race) C++14
21 / 100
2724 ms 263168 KB
#include <bits/stdc++.h>
#include "race.h"
using namespace std;
const int MN = 2e5+5;

struct Edge{
    int x,d;
    Edge(){}
    Edge(int a, int b){
        x = a;
        d = b;
    }
};

vector<Edge> T[MN];
Edge A[MN][101];
Edge B[MN][101];

int DFS(int i, int val, int dis, int r, int K){
    if(dis==K) return val;
    if(dis>K) return MN;
    int res = MN;
    for(auto it : T[i]){
        //cout << i << ' ' << it.x << ' ' << r << '\n';
        if(it.x==r) continue;
        res = min(res,DFS(it.x,val+1,dis+it.d,i,K));
    }
    return res;
}

int TDP(int i, int r, int K){
    int res = MN;
    for(auto it : T[i]){
        if(it.x==r) continue;
        res = min(res,TDP(it.x,i,K));
        for(int j=0; j<=K; j++){
            if(j+it.d<=K){
                int l = A[it.x][j].d+1;
                if(l<A[i][j+it.d].d){
                    B[i][j+it.d] = A[i][j+it.d];
                    A[i][j+it.d] = Edge(it.x,l);
                }
                else if(l<B[i][j+it.d].d) B[i][j+it.d] = Edge(it.x,l);
            }
        }
    }
    for(int k=0; k<=K; k++){
        if(A[i][k].x!=A[i][K-k].x) res = min(res,A[i][k].d+A[i][K-k].d);
        else res = min(res,B[i][k].d+A[i][K-k].d);
    }
    return res;
}

int best_path(int N, int K, int H[][2], int L[])
{
    int ans = MN;
    for(int i=0; i<N-1; i++){
        T[H[i][0]].push_back(Edge(H[i][1],L[i]));
        T[H[i][1]].push_back(Edge(H[i][0],L[i]));
    }
    for(int i=0; i<N; i++)
        for(int j=1; j<=K; j++){
            A[i][j].d = MN;
            B[i][j].d = MN;
        }
    if(K<=100){
        ans = TDP(0,0,K);
    }
    else{
        for(int i=0; i<N; i++){
            ans = min(ans,DFS(i,0,0,i,K));
        }
    }
    if(ans==MN) ans = -1;
    return ans;
}
# Verdict Execution time Memory Grader output
1 Correct 6 ms 5240 KB Output is correct
2 Correct 6 ms 5240 KB Output is correct
3 Correct 6 ms 5240 KB Output is correct
4 Correct 6 ms 5240 KB Output is correct
5 Correct 6 ms 5240 KB Output is correct
6 Correct 6 ms 5212 KB Output is correct
7 Correct 6 ms 5240 KB Output is correct
8 Correct 6 ms 5240 KB Output is correct
9 Correct 6 ms 5244 KB Output is correct
10 Correct 6 ms 5240 KB Output is correct
11 Correct 6 ms 5240 KB Output is correct
12 Correct 6 ms 5240 KB Output is correct
13 Correct 6 ms 5240 KB Output is correct
14 Correct 6 ms 5240 KB Output is correct
15 Correct 6 ms 5240 KB Output is correct
16 Correct 6 ms 5240 KB Output is correct
17 Correct 5 ms 5240 KB Output is correct
18 Correct 6 ms 5240 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 6 ms 5240 KB Output is correct
2 Correct 6 ms 5240 KB Output is correct
3 Correct 6 ms 5240 KB Output is correct
4 Correct 6 ms 5240 KB Output is correct
5 Correct 6 ms 5240 KB Output is correct
6 Correct 6 ms 5212 KB Output is correct
7 Correct 6 ms 5240 KB Output is correct
8 Correct 6 ms 5240 KB Output is correct
9 Correct 6 ms 5244 KB Output is correct
10 Correct 6 ms 5240 KB Output is correct
11 Correct 6 ms 5240 KB Output is correct
12 Correct 6 ms 5240 KB Output is correct
13 Correct 6 ms 5240 KB Output is correct
14 Correct 6 ms 5240 KB Output is correct
15 Correct 6 ms 5240 KB Output is correct
16 Correct 6 ms 5240 KB Output is correct
17 Correct 5 ms 5240 KB Output is correct
18 Correct 6 ms 5240 KB Output is correct
19 Correct 6 ms 5112 KB Output is correct
20 Correct 6 ms 5188 KB Output is correct
21 Correct 17 ms 6748 KB Output is correct
22 Correct 2724 ms 21216 KB Output is correct
23 Correct 2001 ms 18808 KB Output is correct
24 Correct 2374 ms 20344 KB Output is correct
25 Correct 2367 ms 20068 KB Output is correct
26 Correct 895 ms 12152 KB Output is correct
27 Correct 2303 ms 19356 KB Output is correct
28 Correct 537 ms 9904 KB Output is correct
29 Correct 872 ms 11768 KB Output is correct
30 Correct 974 ms 12664 KB Output is correct
31 Correct 1844 ms 17168 KB Output is correct
32 Correct 2025 ms 17912 KB Output is correct
33 Correct 2177 ms 18988 KB Output is correct
34 Correct 1791 ms 15888 KB Output is correct
35 Correct 1986 ms 19360 KB Output is correct
36 Correct 2251 ms 21024 KB Output is correct
37 Correct 1845 ms 19136 KB Output is correct
38 Correct 1228 ms 14712 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 6 ms 5240 KB Output is correct
2 Correct 6 ms 5240 KB Output is correct
3 Correct 6 ms 5240 KB Output is correct
4 Correct 6 ms 5240 KB Output is correct
5 Correct 6 ms 5240 KB Output is correct
6 Correct 6 ms 5212 KB Output is correct
7 Correct 6 ms 5240 KB Output is correct
8 Correct 6 ms 5240 KB Output is correct
9 Correct 6 ms 5244 KB Output is correct
10 Correct 6 ms 5240 KB Output is correct
11 Correct 6 ms 5240 KB Output is correct
12 Correct 6 ms 5240 KB Output is correct
13 Correct 6 ms 5240 KB Output is correct
14 Correct 6 ms 5240 KB Output is correct
15 Correct 6 ms 5240 KB Output is correct
16 Correct 6 ms 5240 KB Output is correct
17 Correct 5 ms 5240 KB Output is correct
18 Correct 6 ms 5240 KB Output is correct
19 Correct 292 ms 168144 KB Output is correct
20 Correct 252 ms 169336 KB Output is correct
21 Correct 314 ms 169512 KB Output is correct
22 Correct 354 ms 169520 KB Output is correct
23 Correct 286 ms 169720 KB Output is correct
24 Correct 333 ms 169680 KB Output is correct
25 Correct 412 ms 174584 KB Output is correct
26 Correct 250 ms 179872 KB Output is correct
27 Runtime error 324 ms 263168 KB Execution killed with signal 9 (could be triggered by violating memory limits)
28 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 6 ms 5240 KB Output is correct
2 Correct 6 ms 5240 KB Output is correct
3 Correct 6 ms 5240 KB Output is correct
4 Correct 6 ms 5240 KB Output is correct
5 Correct 6 ms 5240 KB Output is correct
6 Correct 6 ms 5212 KB Output is correct
7 Correct 6 ms 5240 KB Output is correct
8 Correct 6 ms 5240 KB Output is correct
9 Correct 6 ms 5244 KB Output is correct
10 Correct 6 ms 5240 KB Output is correct
11 Correct 6 ms 5240 KB Output is correct
12 Correct 6 ms 5240 KB Output is correct
13 Correct 6 ms 5240 KB Output is correct
14 Correct 6 ms 5240 KB Output is correct
15 Correct 6 ms 5240 KB Output is correct
16 Correct 6 ms 5240 KB Output is correct
17 Correct 5 ms 5240 KB Output is correct
18 Correct 6 ms 5240 KB Output is correct
19 Correct 6 ms 5112 KB Output is correct
20 Correct 6 ms 5188 KB Output is correct
21 Correct 17 ms 6748 KB Output is correct
22 Correct 2724 ms 21216 KB Output is correct
23 Correct 2001 ms 18808 KB Output is correct
24 Correct 2374 ms 20344 KB Output is correct
25 Correct 2367 ms 20068 KB Output is correct
26 Correct 895 ms 12152 KB Output is correct
27 Correct 2303 ms 19356 KB Output is correct
28 Correct 537 ms 9904 KB Output is correct
29 Correct 872 ms 11768 KB Output is correct
30 Correct 974 ms 12664 KB Output is correct
31 Correct 1844 ms 17168 KB Output is correct
32 Correct 2025 ms 17912 KB Output is correct
33 Correct 2177 ms 18988 KB Output is correct
34 Correct 1791 ms 15888 KB Output is correct
35 Correct 1986 ms 19360 KB Output is correct
36 Correct 2251 ms 21024 KB Output is correct
37 Correct 1845 ms 19136 KB Output is correct
38 Correct 1228 ms 14712 KB Output is correct
39 Correct 292 ms 168144 KB Output is correct
40 Correct 252 ms 169336 KB Output is correct
41 Correct 314 ms 169512 KB Output is correct
42 Correct 354 ms 169520 KB Output is correct
43 Correct 286 ms 169720 KB Output is correct
44 Correct 333 ms 169680 KB Output is correct
45 Correct 412 ms 174584 KB Output is correct
46 Correct 250 ms 179872 KB Output is correct
47 Runtime error 324 ms 263168 KB Execution killed with signal 9 (could be triggered by violating memory limits)
48 Halted 0 ms 0 KB -