Submission #877877

# Submission time Handle Problem Language Result Execution time Memory
877877 2023-11-23T19:46:35 Z Matjaz Race (IOI11_race) C++14
43 / 100
3000 ms 118368 KB
#include "race.h"
#include <vector>
#include <algorithm>
#include <iostream>
#include <map>
using namespace std;

struct edge{
    int u;
    int l;
};

int N,K;
vector<vector<edge> > s;

int best;


vector<int> pathssmallK(int x, int p){
    
    vector<int> possible(K+1, N);
    possible[0] = 0;
    
    for (int i=0;i<s[x].size();i++){
        if (s[x][i].u == p) continue;
        vector<int> pths = pathssmallK(s[x][i].u, x);
        for (int j=0;j<=K;j++){
            if (pths[j] == N) continue;
            if (j + s[x][i].l > K) continue;
            if (possible[K - j - s[x][i].l] != N){
                best = min(best, possible[K - j - s[x][i].l] + 1 + pths[j]);
            }
        }
        
        for (int j=0;j<=K;j++){
            if (pths[j] == N) continue;
            if (j + s[x][i].l > K) continue;
            possible[j + s[x][i].l] = min(possible[j + s[x][i].l], 1 + pths[j]);
        }
    }
    
    /*cout << x << ": ";
    for (int i=0;i<K+1;i++) cout << possible[i] << " ";
    cout << endl;*/
    
    return possible;
}

map<int,int> paths(int x, int p){
    
    map<int,int> possible;
    possible[0] = 0;
    
    for (int i=0;i<s[x].size();i++){
        if (s[x][i].u == p) continue;
        map<int, int> pths = paths(s[x][i].u, x);
        int l = s[x][i].l;
        
        for (map<int,int>::iterator it = pths.begin(); it != pths.end(); it++){
            if (possible.count(K - l - it -> first) > 0){
                best = min(best, 1 + it -> second + possible[K - l - it -> first]);
                
            }
        }
        
        for (map<int,int>::iterator it = pths.begin(); it != pths.end(); it++){
            if (l + it -> first > K) continue;
            if (possible.count(l + it -> first) > 0)
                possible[l + it -> first] = min(possible[l + it -> first], 1 + it -> second); else possible[l + it -> first] = 1 + it -> second;
        }
    }
    
   /* cout << x << ": " << endl;
    for (map<int,int>::iterator it = possible.begin(); it != possible.end(); it++) cout << it -> first << " " << it -> second << endl;
    cout << endl; */
    
    return possible;
}









int best_path(int _N, int _K, int H[][2], int L[]){
    N = _N; K = _K;
    s.assign(N, vector<edge> ());
    for (int i=0;i<N-1;i++){
        edge e,f;
        e.l = L[i];
        e.u = H[i][0];
        f.l = L[i];
        f.u = H[i][1];
        s[H[i][1]].push_back(e);
        s[H[i][0]].push_back(f);
    }
    
    best = N;
    if (K <= 100) pathssmallK(0, -1); else
    paths(0, -1);
    
    if (best == N) return -1; else return best;
}

Compilation message

race.cpp: In function 'std::vector<int> pathssmallK(int, int)':
race.cpp:24:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<edge>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   24 |     for (int i=0;i<s[x].size();i++){
      |                  ~^~~~~~~~~~~~
race.cpp: In function 'std::map<int, int> paths(int, int)':
race.cpp:54:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<edge>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   54 |     for (int i=0;i<s[x].size();i++){
      |                  ~^~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2396 KB Output is correct
2 Correct 1 ms 2396 KB Output is correct
3 Correct 1 ms 2396 KB Output is correct
4 Correct 1 ms 2396 KB Output is correct
5 Correct 1 ms 2396 KB Output is correct
6 Correct 0 ms 2392 KB Output is correct
7 Correct 1 ms 2396 KB Output is correct
8 Correct 0 ms 2396 KB Output is correct
9 Correct 1 ms 2396 KB Output is correct
10 Correct 1 ms 2392 KB Output is correct
11 Correct 1 ms 2396 KB Output is correct
12 Correct 0 ms 2396 KB Output is correct
13 Correct 1 ms 2396 KB Output is correct
14 Correct 1 ms 2396 KB Output is correct
15 Correct 1 ms 2492 KB Output is correct
16 Correct 1 ms 2396 KB Output is correct
17 Correct 1 ms 2396 KB Output is correct
18 Correct 1 ms 2392 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2396 KB Output is correct
2 Correct 1 ms 2396 KB Output is correct
3 Correct 1 ms 2396 KB Output is correct
4 Correct 1 ms 2396 KB Output is correct
5 Correct 1 ms 2396 KB Output is correct
6 Correct 0 ms 2392 KB Output is correct
7 Correct 1 ms 2396 KB Output is correct
8 Correct 0 ms 2396 KB Output is correct
9 Correct 1 ms 2396 KB Output is correct
10 Correct 1 ms 2392 KB Output is correct
11 Correct 1 ms 2396 KB Output is correct
12 Correct 0 ms 2396 KB Output is correct
13 Correct 1 ms 2396 KB Output is correct
14 Correct 1 ms 2396 KB Output is correct
15 Correct 1 ms 2492 KB Output is correct
16 Correct 1 ms 2396 KB Output is correct
17 Correct 1 ms 2396 KB Output is correct
18 Correct 1 ms 2392 KB Output is correct
19 Correct 1 ms 2396 KB Output is correct
20 Correct 1 ms 2396 KB Output is correct
21 Correct 1 ms 2396 KB Output is correct
22 Correct 1 ms 2396 KB Output is correct
23 Correct 2 ms 2548 KB Output is correct
24 Correct 1 ms 2396 KB Output is correct
25 Correct 2 ms 2440 KB Output is correct
26 Correct 1 ms 2396 KB Output is correct
27 Correct 1 ms 2392 KB Output is correct
28 Correct 2 ms 2396 KB Output is correct
29 Correct 2 ms 2392 KB Output is correct
30 Correct 2 ms 2396 KB Output is correct
31 Correct 2 ms 2396 KB Output is correct
32 Correct 2 ms 2396 KB Output is correct
33 Correct 4 ms 2652 KB Output is correct
34 Correct 2 ms 2396 KB Output is correct
35 Correct 3 ms 2508 KB Output is correct
36 Correct 3 ms 2652 KB Output is correct
37 Correct 7 ms 2652 KB Output is correct
38 Correct 5 ms 2652 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2396 KB Output is correct
2 Correct 1 ms 2396 KB Output is correct
3 Correct 1 ms 2396 KB Output is correct
4 Correct 1 ms 2396 KB Output is correct
5 Correct 1 ms 2396 KB Output is correct
6 Correct 0 ms 2392 KB Output is correct
7 Correct 1 ms 2396 KB Output is correct
8 Correct 0 ms 2396 KB Output is correct
9 Correct 1 ms 2396 KB Output is correct
10 Correct 1 ms 2392 KB Output is correct
11 Correct 1 ms 2396 KB Output is correct
12 Correct 0 ms 2396 KB Output is correct
13 Correct 1 ms 2396 KB Output is correct
14 Correct 1 ms 2396 KB Output is correct
15 Correct 1 ms 2492 KB Output is correct
16 Correct 1 ms 2396 KB Output is correct
17 Correct 1 ms 2396 KB Output is correct
18 Correct 1 ms 2392 KB Output is correct
19 Correct 64 ms 10584 KB Output is correct
20 Correct 70 ms 10580 KB Output is correct
21 Correct 64 ms 10732 KB Output is correct
22 Correct 61 ms 10584 KB Output is correct
23 Correct 58 ms 10832 KB Output is correct
24 Correct 55 ms 10832 KB Output is correct
25 Correct 90 ms 37200 KB Output is correct
26 Correct 86 ms 61800 KB Output is correct
27 Correct 139 ms 17180 KB Output is correct
28 Correct 201 ms 118368 KB Output is correct
29 Correct 185 ms 108112 KB Output is correct
30 Correct 146 ms 17176 KB Output is correct
31 Correct 137 ms 17188 KB Output is correct
32 Correct 157 ms 17664 KB Output is correct
33 Correct 137 ms 17056 KB Output is correct
34 Correct 133 ms 16932 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2396 KB Output is correct
2 Correct 1 ms 2396 KB Output is correct
3 Correct 1 ms 2396 KB Output is correct
4 Correct 1 ms 2396 KB Output is correct
5 Correct 1 ms 2396 KB Output is correct
6 Correct 0 ms 2392 KB Output is correct
7 Correct 1 ms 2396 KB Output is correct
8 Correct 0 ms 2396 KB Output is correct
9 Correct 1 ms 2396 KB Output is correct
10 Correct 1 ms 2392 KB Output is correct
11 Correct 1 ms 2396 KB Output is correct
12 Correct 0 ms 2396 KB Output is correct
13 Correct 1 ms 2396 KB Output is correct
14 Correct 1 ms 2396 KB Output is correct
15 Correct 1 ms 2492 KB Output is correct
16 Correct 1 ms 2396 KB Output is correct
17 Correct 1 ms 2396 KB Output is correct
18 Correct 1 ms 2392 KB Output is correct
19 Correct 1 ms 2396 KB Output is correct
20 Correct 1 ms 2396 KB Output is correct
21 Correct 1 ms 2396 KB Output is correct
22 Correct 1 ms 2396 KB Output is correct
23 Correct 2 ms 2548 KB Output is correct
24 Correct 1 ms 2396 KB Output is correct
25 Correct 2 ms 2440 KB Output is correct
26 Correct 1 ms 2396 KB Output is correct
27 Correct 1 ms 2392 KB Output is correct
28 Correct 2 ms 2396 KB Output is correct
29 Correct 2 ms 2392 KB Output is correct
30 Correct 2 ms 2396 KB Output is correct
31 Correct 2 ms 2396 KB Output is correct
32 Correct 2 ms 2396 KB Output is correct
33 Correct 4 ms 2652 KB Output is correct
34 Correct 2 ms 2396 KB Output is correct
35 Correct 3 ms 2508 KB Output is correct
36 Correct 3 ms 2652 KB Output is correct
37 Correct 7 ms 2652 KB Output is correct
38 Correct 5 ms 2652 KB Output is correct
39 Correct 64 ms 10584 KB Output is correct
40 Correct 70 ms 10580 KB Output is correct
41 Correct 64 ms 10732 KB Output is correct
42 Correct 61 ms 10584 KB Output is correct
43 Correct 58 ms 10832 KB Output is correct
44 Correct 55 ms 10832 KB Output is correct
45 Correct 90 ms 37200 KB Output is correct
46 Correct 86 ms 61800 KB Output is correct
47 Correct 139 ms 17180 KB Output is correct
48 Correct 201 ms 118368 KB Output is correct
49 Correct 185 ms 108112 KB Output is correct
50 Correct 146 ms 17176 KB Output is correct
51 Correct 137 ms 17188 KB Output is correct
52 Correct 157 ms 17664 KB Output is correct
53 Correct 137 ms 17056 KB Output is correct
54 Correct 133 ms 16932 KB Output is correct
55 Correct 14 ms 3416 KB Output is correct
56 Correct 7 ms 3160 KB Output is correct
57 Correct 55 ms 11884 KB Output is correct
58 Correct 35 ms 11900 KB Output is correct
59 Execution timed out 3034 ms 38484 KB Time limit exceeded
60 Halted 0 ms 0 KB -