Submission #142845

# Submission time Handle Problem Language Result Execution time Memory
142845 2019-08-11T13:12:48 Z Milki Dreaming (IOI13_dreaming) C++14
54 / 100
109 ms 15572 KB
//#ifndef DREAMING_H_INCLUDED
//#define DREAMING_H_INCLUDED

#include "dreaming.h"
#include<bits/stdc++.h>
using namespace std;

#define FOR(i, a, b) for(int i = a; i < b; ++i)
#define REP(i, n) FOR(i, 0, n)
#define _ << " " <<
#define sz(x) ((int) x.size())
#define pb(x) push_back(x)
#define TRACE(x) cerr << #x << " = " << x << endl

typedef long long ll;
typedef pair<int, int> point;

const int MAXN = 1e5 + 5;

vector <point> E[MAXN];
vector <int> component[MAXN];
int boja[MAXN], dist[MAXN], dep[MAXN];
point par[MAXN], mx[MAXN];

void color(int x, int Time){
  boja[x] = Time;
  component[Time].pb(x);
  for(auto e : E[x]){
    if(boja[e.first] != -1) continue;
    color(e.first, Time);
  }
}

point find_furthest(int cmp, int x){
  for(auto it : component[cmp])
    dist[it] = 0;

  queue<int> Q;
  Q.push(x);

  point ret = point(0, 0);
  while(!Q.empty()){
    int nx = Q.front(); Q.pop();
    for(auto e : E[nx]){
      if(dist[e.first] || e.first == x)
        continue;

      par[e.first] = point(nx, e.second);
      dep[e.first] = dep[nx] + 1;
      dist[e.first] = dist[nx] + e.second;
      ret = max(ret, point(dist[e.first], e.first));
      Q.push(e.first);
    }
  }

  return ret;
}

int travelTime(int N, int M, int L, int A[], int B[], int T[]) {
  REP(i, M){
    E[ A[i] ].pb( point( B[i], T[i] ) );
    E[ B[i] ].pb( point( A[i], T[i] ) );
  }

  memset(boja, -1, sizeof(boja));
  int Time = 0;
  REP(i, N)
    if(boja[i] == -1)
      color(i, Time ++);

  int ret = 0;
  REP(i, Time){
    int a = find_furthest(i, component[i][0]).second;
    point najdalji = find_furthest(i, a);
    int b = najdalji.second, d = najdalji.first;

    if(dep[a] < dep[b])
      swap(a, b);

    ret = max(ret, d);
    mx[i] = point(d, a);

    deque<point> lt, rt;

    while(dep[a] != dep[b]){
      lt.push_back(par[a]);
      a = par[a].first;
    }

    while(a != b){
      lt.push_back(par[a]);
      a = par[a].first;

      rt.push_front(point(b, par[b].second));
      b = par[b].first;
    }

    int sum = 0;
    for(auto it : lt){
      sum += it.second;
      mx[i] = min(mx[i], point(max(d - sum, sum), it.first));
    }
    for(auto it : rt){
      sum += it.second;
      mx[i] = min(mx[i], point(max(d - sum, sum), it.first));
    }

    //mx[i] = max(mx[i], find_furthest(i, mx[i].second));
  }

  sort(mx, mx + Time, greater<point>());
  //TRACE(mx[0].first); TRACE(mx[1].first); TRACE(L);

  if(Time == 1)
    return ret;
  else if(Time == 2)
    return max(ret, mx[0].first + mx[1].first + L);
  else
    return max(mx[1].first + mx[2].first + 2 * L, max(ret, mx[0].first + mx[1].first + L));
}

//#endif // DREAMING_H_INCLUDED
# Verdict Execution time Memory Grader output
1 Correct 80 ms 14712 KB Output is correct
2 Correct 81 ms 14600 KB Output is correct
3 Correct 51 ms 12404 KB Output is correct
4 Correct 16 ms 6904 KB Output is correct
5 Correct 14 ms 6392 KB Output is correct
6 Correct 23 ms 7672 KB Output is correct
7 Correct 7 ms 5496 KB Output is correct
8 Correct 39 ms 9428 KB Output is correct
9 Correct 49 ms 11172 KB Output is correct
10 Correct 7 ms 5496 KB Output is correct
11 Correct 71 ms 12180 KB Output is correct
12 Correct 97 ms 13448 KB Output is correct
13 Correct 7 ms 5496 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 80 ms 14712 KB Output is correct
2 Correct 81 ms 14600 KB Output is correct
3 Correct 51 ms 12404 KB Output is correct
4 Correct 16 ms 6904 KB Output is correct
5 Correct 14 ms 6392 KB Output is correct
6 Correct 23 ms 7672 KB Output is correct
7 Correct 7 ms 5496 KB Output is correct
8 Correct 39 ms 9428 KB Output is correct
9 Correct 49 ms 11172 KB Output is correct
10 Correct 7 ms 5496 KB Output is correct
11 Correct 71 ms 12180 KB Output is correct
12 Correct 97 ms 13448 KB Output is correct
13 Correct 7 ms 5496 KB Output is correct
14 Correct 6 ms 5496 KB Output is correct
15 Correct 6 ms 5496 KB Output is correct
16 Correct 6 ms 5372 KB Output is correct
17 Correct 7 ms 5496 KB Output is correct
18 Correct 7 ms 5368 KB Output is correct
19 Correct 7 ms 5496 KB Output is correct
20 Correct 6 ms 5368 KB Output is correct
21 Correct 7 ms 5368 KB Output is correct
22 Correct 6 ms 5500 KB Output is correct
23 Correct 7 ms 5496 KB Output is correct
24 Correct 6 ms 5496 KB Output is correct
25 Correct 6 ms 5496 KB Output is correct
26 Correct 6 ms 5496 KB Output is correct
27 Correct 6 ms 5496 KB Output is correct
28 Correct 7 ms 5484 KB Output is correct
29 Correct 7 ms 5496 KB Output is correct
30 Correct 7 ms 5496 KB Output is correct
31 Correct 6 ms 5372 KB Output is correct
32 Correct 7 ms 5496 KB Output is correct
33 Correct 6 ms 5368 KB Output is correct
34 Correct 6 ms 5496 KB Output is correct
35 Correct 7 ms 5496 KB Output is correct
36 Correct 7 ms 5496 KB Output is correct
37 Correct 7 ms 5496 KB Output is correct
38 Correct 7 ms 5496 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 80 ms 14712 KB Output is correct
2 Correct 81 ms 14600 KB Output is correct
3 Correct 51 ms 12404 KB Output is correct
4 Correct 16 ms 6904 KB Output is correct
5 Correct 14 ms 6392 KB Output is correct
6 Correct 23 ms 7672 KB Output is correct
7 Correct 7 ms 5496 KB Output is correct
8 Correct 39 ms 9428 KB Output is correct
9 Correct 49 ms 11172 KB Output is correct
10 Correct 7 ms 5496 KB Output is correct
11 Correct 71 ms 12180 KB Output is correct
12 Correct 97 ms 13448 KB Output is correct
13 Correct 7 ms 5496 KB Output is correct
14 Correct 6 ms 5496 KB Output is correct
15 Correct 6 ms 5496 KB Output is correct
16 Correct 6 ms 5372 KB Output is correct
17 Correct 7 ms 5496 KB Output is correct
18 Correct 7 ms 5368 KB Output is correct
19 Correct 7 ms 5496 KB Output is correct
20 Correct 6 ms 5368 KB Output is correct
21 Correct 7 ms 5368 KB Output is correct
22 Correct 6 ms 5500 KB Output is correct
23 Correct 7 ms 5496 KB Output is correct
24 Correct 6 ms 5496 KB Output is correct
25 Correct 6 ms 5496 KB Output is correct
26 Correct 6 ms 5496 KB Output is correct
27 Correct 6 ms 5496 KB Output is correct
28 Correct 7 ms 5484 KB Output is correct
29 Correct 7 ms 5496 KB Output is correct
30 Correct 7 ms 5496 KB Output is correct
31 Correct 6 ms 5372 KB Output is correct
32 Correct 7 ms 5496 KB Output is correct
33 Correct 6 ms 5368 KB Output is correct
34 Correct 6 ms 5496 KB Output is correct
35 Correct 7 ms 5496 KB Output is correct
36 Correct 7 ms 5496 KB Output is correct
37 Correct 7 ms 5496 KB Output is correct
38 Correct 7 ms 5496 KB Output is correct
39 Correct 76 ms 15572 KB Output is correct
40 Correct 83 ms 15352 KB Output is correct
41 Correct 52 ms 13044 KB Output is correct
42 Correct 16 ms 6904 KB Output is correct
43 Correct 7 ms 5368 KB Output is correct
44 Correct 6 ms 5496 KB Output is correct
45 Correct 7 ms 5496 KB Output is correct
46 Correct 7 ms 5468 KB Output is correct
47 Correct 7 ms 5496 KB Output is correct
48 Correct 7 ms 5496 KB Output is correct
49 Correct 9 ms 5368 KB Output is correct
50 Correct 7 ms 5496 KB Output is correct
51 Correct 7 ms 5496 KB Output is correct
52 Correct 7 ms 5368 KB Output is correct
53 Correct 7 ms 5496 KB Output is correct
54 Correct 7 ms 5496 KB Output is correct
55 Correct 6 ms 5368 KB Output is correct
56 Correct 6 ms 5368 KB Output is correct
57 Correct 100 ms 13988 KB Output is correct
58 Correct 109 ms 14036 KB Output is correct
59 Correct 96 ms 13824 KB Output is correct
60 Correct 91 ms 13940 KB Output is correct
61 Correct 94 ms 13932 KB Output is correct
62 Correct 94 ms 14088 KB Output is correct
63 Correct 86 ms 13684 KB Output is correct
64 Incorrect 95 ms 13816 KB Output isn't correct
65 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 84 ms 12024 KB Output is correct
2 Correct 86 ms 12080 KB Output is correct
3 Correct 87 ms 12080 KB Output is correct
4 Correct 85 ms 12024 KB Output is correct
5 Correct 83 ms 11988 KB Output is correct
6 Correct 86 ms 12432 KB Output is correct
7 Correct 82 ms 12408 KB Output is correct
8 Correct 78 ms 11940 KB Output is correct
9 Correct 77 ms 11896 KB Output is correct
10 Correct 85 ms 12244 KB Output is correct
11 Correct 7 ms 5496 KB Output is correct
12 Correct 63 ms 10872 KB Output is correct
13 Correct 63 ms 11000 KB Output is correct
14 Correct 64 ms 10872 KB Output is correct
15 Correct 63 ms 10872 KB Output is correct
16 Correct 63 ms 10844 KB Output is correct
17 Correct 63 ms 10232 KB Output is correct
18 Correct 64 ms 10872 KB Output is correct
19 Correct 68 ms 10876 KB Output is correct
20 Correct 7 ms 5496 KB Output is correct
21 Correct 6 ms 5368 KB Output is correct
22 Correct 8 ms 5624 KB Output is correct
23 Correct 63 ms 10776 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 80 ms 14712 KB Output is correct
2 Correct 81 ms 14600 KB Output is correct
3 Correct 51 ms 12404 KB Output is correct
4 Correct 16 ms 6904 KB Output is correct
5 Correct 14 ms 6392 KB Output is correct
6 Correct 23 ms 7672 KB Output is correct
7 Correct 7 ms 5496 KB Output is correct
8 Correct 39 ms 9428 KB Output is correct
9 Correct 49 ms 11172 KB Output is correct
10 Correct 7 ms 5496 KB Output is correct
11 Correct 71 ms 12180 KB Output is correct
12 Correct 97 ms 13448 KB Output is correct
13 Correct 7 ms 5496 KB Output is correct
14 Correct 7 ms 5496 KB Output is correct
15 Correct 8 ms 5628 KB Output is correct
16 Correct 8 ms 5624 KB Output is correct
17 Correct 7 ms 5496 KB Output is correct
18 Correct 8 ms 5624 KB Output is correct
19 Correct 8 ms 5752 KB Output is correct
20 Correct 7 ms 5496 KB Output is correct
21 Correct 11 ms 5628 KB Output is correct
22 Correct 9 ms 5632 KB Output is correct
23 Correct 6 ms 5368 KB Output is correct
24 Correct 6 ms 5368 KB Output is correct
25 Correct 6 ms 5496 KB Output is correct
26 Correct 6 ms 5368 KB Output is correct
27 Correct 7 ms 5496 KB Output is correct
28 Correct 7 ms 5496 KB Output is correct
29 Correct 6 ms 5496 KB Output is correct
30 Correct 6 ms 5372 KB Output is correct
31 Correct 7 ms 5496 KB Output is correct
32 Correct 7 ms 5496 KB Output is correct
33 Correct 6 ms 5496 KB Output is correct
34 Correct 7 ms 5496 KB Output is correct
35 Correct 7 ms 5496 KB Output is correct
36 Correct 6 ms 5496 KB Output is correct
37 Correct 6 ms 5368 KB Output is correct
38 Correct 6 ms 5368 KB Output is correct
39 Correct 7 ms 5496 KB Output is correct
40 Correct 7 ms 5496 KB Output is correct
41 Correct 6 ms 5368 KB Output is correct
42 Correct 8 ms 5752 KB Output is correct
43 Correct 8 ms 5752 KB Output is correct
44 Correct 9 ms 5624 KB Output is correct
45 Correct 9 ms 5624 KB Output is correct
46 Correct 8 ms 5756 KB Output is correct
47 Correct 9 ms 5752 KB Output is correct
48 Correct 8 ms 5624 KB Output is correct
49 Correct 9 ms 5624 KB Output is correct
50 Correct 9 ms 5752 KB Output is correct
51 Correct 8 ms 5624 KB Output is correct
52 Correct 8 ms 5624 KB Output is correct
53 Correct 9 ms 5624 KB Output is correct
54 Correct 15 ms 5624 KB Output is correct
55 Correct 10 ms 5752 KB Output is correct
56 Correct 9 ms 5624 KB Output is correct
57 Correct 8 ms 5752 KB Output is correct
58 Correct 8 ms 5624 KB Output is correct
59 Correct 8 ms 5624 KB Output is correct
60 Correct 8 ms 5752 KB Output is correct
61 Correct 8 ms 5752 KB Output is correct
62 Correct 8 ms 5752 KB Output is correct
63 Correct 8 ms 5624 KB Output is correct
64 Correct 8 ms 5752 KB Output is correct
65 Correct 9 ms 5624 KB Output is correct
66 Correct 8 ms 5624 KB Output is correct
67 Correct 8 ms 5624 KB Output is correct
68 Correct 8 ms 5624 KB Output is correct
69 Correct 8 ms 5624 KB Output is correct
70 Correct 8 ms 5752 KB Output is correct
71 Correct 9 ms 5752 KB Output is correct
72 Correct 8 ms 5624 KB Output is correct
73 Correct 8 ms 5624 KB Output is correct
74 Correct 8 ms 5624 KB Output is correct
75 Correct 8 ms 5752 KB Output is correct
76 Correct 9 ms 5624 KB Output is correct
77 Correct 9 ms 5624 KB Output is correct
78 Correct 8 ms 5624 KB Output is correct
79 Correct 9 ms 5624 KB Output is correct
80 Correct 8 ms 5624 KB Output is correct
81 Correct 8 ms 5624 KB Output is correct
82 Correct 8 ms 5624 KB Output is correct
83 Correct 8 ms 5624 KB Output is correct
84 Correct 8 ms 5624 KB Output is correct
85 Correct 8 ms 5624 KB Output is correct
86 Correct 8 ms 5624 KB Output is correct
87 Correct 8 ms 5624 KB Output is correct
88 Correct 8 ms 5620 KB Output is correct
89 Correct 8 ms 5624 KB Output is correct
90 Correct 6 ms 5368 KB Output is correct
91 Correct 6 ms 5368 KB Output is correct
92 Correct 6 ms 5496 KB Output is correct
93 Correct 6 ms 5496 KB Output is correct
94 Correct 7 ms 5496 KB Output is correct
95 Correct 8 ms 5584 KB Output is correct
96 Correct 8 ms 5368 KB Output is correct
97 Correct 7 ms 5496 KB Output is correct
98 Correct 6 ms 5368 KB Output is correct
99 Correct 7 ms 5496 KB Output is correct
100 Correct 7 ms 5496 KB Output is correct
101 Correct 7 ms 5496 KB Output is correct
102 Correct 7 ms 5496 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 80 ms 14712 KB Output is correct
2 Correct 81 ms 14600 KB Output is correct
3 Correct 51 ms 12404 KB Output is correct
4 Correct 16 ms 6904 KB Output is correct
5 Correct 14 ms 6392 KB Output is correct
6 Correct 23 ms 7672 KB Output is correct
7 Correct 7 ms 5496 KB Output is correct
8 Correct 39 ms 9428 KB Output is correct
9 Correct 49 ms 11172 KB Output is correct
10 Correct 7 ms 5496 KB Output is correct
11 Correct 71 ms 12180 KB Output is correct
12 Correct 97 ms 13448 KB Output is correct
13 Correct 7 ms 5496 KB Output is correct
14 Correct 6 ms 5496 KB Output is correct
15 Correct 6 ms 5496 KB Output is correct
16 Correct 6 ms 5372 KB Output is correct
17 Correct 7 ms 5496 KB Output is correct
18 Correct 7 ms 5368 KB Output is correct
19 Correct 7 ms 5496 KB Output is correct
20 Correct 6 ms 5368 KB Output is correct
21 Correct 7 ms 5368 KB Output is correct
22 Correct 6 ms 5500 KB Output is correct
23 Correct 7 ms 5496 KB Output is correct
24 Correct 6 ms 5496 KB Output is correct
25 Correct 6 ms 5496 KB Output is correct
26 Correct 6 ms 5496 KB Output is correct
27 Correct 6 ms 5496 KB Output is correct
28 Correct 7 ms 5484 KB Output is correct
29 Correct 7 ms 5496 KB Output is correct
30 Correct 7 ms 5496 KB Output is correct
31 Correct 6 ms 5372 KB Output is correct
32 Correct 7 ms 5496 KB Output is correct
33 Correct 6 ms 5368 KB Output is correct
34 Correct 6 ms 5496 KB Output is correct
35 Correct 7 ms 5496 KB Output is correct
36 Correct 7 ms 5496 KB Output is correct
37 Correct 7 ms 5496 KB Output is correct
38 Correct 7 ms 5496 KB Output is correct
39 Correct 76 ms 15572 KB Output is correct
40 Correct 83 ms 15352 KB Output is correct
41 Correct 52 ms 13044 KB Output is correct
42 Correct 16 ms 6904 KB Output is correct
43 Correct 7 ms 5368 KB Output is correct
44 Correct 6 ms 5496 KB Output is correct
45 Correct 7 ms 5496 KB Output is correct
46 Correct 7 ms 5468 KB Output is correct
47 Correct 7 ms 5496 KB Output is correct
48 Correct 7 ms 5496 KB Output is correct
49 Correct 9 ms 5368 KB Output is correct
50 Correct 7 ms 5496 KB Output is correct
51 Correct 7 ms 5496 KB Output is correct
52 Correct 7 ms 5368 KB Output is correct
53 Correct 7 ms 5496 KB Output is correct
54 Correct 7 ms 5496 KB Output is correct
55 Correct 6 ms 5368 KB Output is correct
56 Correct 6 ms 5368 KB Output is correct
57 Correct 100 ms 13988 KB Output is correct
58 Correct 109 ms 14036 KB Output is correct
59 Correct 96 ms 13824 KB Output is correct
60 Correct 91 ms 13940 KB Output is correct
61 Correct 94 ms 13932 KB Output is correct
62 Correct 94 ms 14088 KB Output is correct
63 Correct 86 ms 13684 KB Output is correct
64 Incorrect 95 ms 13816 KB Output isn't correct
65 Halted 0 ms 0 KB -