Submission #551218

# Submission time Handle Problem Language Result Execution time Memory
551218 2022-04-20T05:57:54 Z AriaH Race (IOI11_race) C++17
100 / 100
993 ms 135304 KB
#include "race.h"
/* Im the best and i work like that */

#pragma GCC optimize("Ofast")

#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef long double ld;
typedef pair < int, int > pii;
typedef pair < ll, ll > pll;

#define F first
#define S second
#define all(x) x.begin(),x.end()
#define Mp make_pair
#define point complex
#define endl '\n'
#define SZ(x) (int)x.size()
#define fast_io ios::sync_with_stdio(0), cin.tie(0), cout.tie(0)
#define file_io freopen("input.txt", "r+", stdin); freopen("output.txt", "w+", stdout);
#define mashtali return cout << "Hello, World!", 0;

const int N = 1e6 + 10;
const int LOG = 20;
const ll mod = 1e9 + 7;
const ll inf = 8e18;
const double pi = acos(-1);
const ld eps = 1e-18;
const ld one = 1.;

ll pw(ll a, ll b, ll M, ll ret = 1) { if(a == 0) return 0; a %= M; while(b) { ret = (b & 1? ret * a % M : ret), a = a * a % M, b >>= 1; } return ret % M; }

mt19937 rng(time(nullptr));

vector < pii > G[N];

vector < int > S[N];

multiset < int > st[N];

int n, k, tot, sub[N], hide[N];

ll dis[N], H[N];

void pre(int v, int P = -1)
{
  sub[v] = 1;
  for(auto [u, c] : G[v])
  {
    if(hide[u] || u == P) continue;
    pre(u, v);
    sub[v] += sub[u];
  }
}

int find(int v, int P, int _n)
{
  for(auto [u, c] : G[v])
  {
    if(hide[u] || u == P) continue;
    if(sub[u] * 2 > _n) return find(u, v, _n);
  }
  return v;
}

void calc(int v, int P, int jad)
{
  S[jad].push_back(v);
  if(dis[v] < N)
  {
    st[dis[v]].insert(H[v]);
  }
  for(auto [u, c] : G[v])
  {
    if(hide[u] || u == P) continue;
    H[u] = H[v] + 1;
    dis[u] = dis[v] + c;
    calc(u, v, jad);
  }
}

void dec(int v)
{
  pre(v);
  int _n = sub[v];
  int cen = find(v, -1, _n);
  for(auto [u, c] : G[cen])
  {
    if(hide[u]) continue;
    dis[u] = c;
    H[u] = 1;
    calc(u, cen, u);
  }
  if(SZ(st[k]))
  {
    tot = min(tot, *st[k].begin());
  }
  for(auto [u, c] : G[cen])
  {
    if(hide[u]) continue;
    for(auto node : S[u])
    {
      if(dis[node] >= N) continue;
      st[dis[node]].erase(st[dis[node]].find(H[node]));
    }
    for(auto node : S[u])
    {
      if(dis[node] >= k) continue;
      if(SZ(st[k - dis[node]]))
      {
        tot = min((ll)tot, H[node] + *st[k - dis[node]].begin());
      }
    }
    S[u].clear();
  }
  hide[cen] = 1;
  for(auto [u, c] : G[cen])
  {
    if(hide[u]) continue;
    dec(u);
  }
}

int best_path(int _n, int K, int H[][2], int L[])
{
  tot = 1e9;
  n = _n;
  k = K;
  for(int i = 0; i < n - 1; i ++)
  {
    int a = H[i][0], b = H[i][1];
    G[a].push_back(Mp(b, L[i]));
    G[b].push_back(Mp(a, L[i]));
  }
  dec(1);
  if(tot == 1e9)
  {
    return -1;
  }
  return tot;
}
# Verdict Execution time Memory Grader output
1 Correct 50 ms 94272 KB Output is correct
2 Correct 49 ms 94248 KB Output is correct
3 Correct 51 ms 94280 KB Output is correct
4 Correct 48 ms 94296 KB Output is correct
5 Correct 50 ms 94212 KB Output is correct
6 Correct 49 ms 94156 KB Output is correct
7 Correct 50 ms 94180 KB Output is correct
8 Correct 48 ms 94284 KB Output is correct
9 Correct 54 ms 94256 KB Output is correct
10 Correct 48 ms 94248 KB Output is correct
11 Correct 48 ms 94216 KB Output is correct
12 Correct 50 ms 94280 KB Output is correct
13 Correct 47 ms 94156 KB Output is correct
14 Correct 49 ms 94308 KB Output is correct
15 Correct 54 ms 94200 KB Output is correct
16 Correct 48 ms 94284 KB Output is correct
17 Correct 48 ms 94172 KB Output is correct
18 Correct 53 ms 94232 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 50 ms 94272 KB Output is correct
2 Correct 49 ms 94248 KB Output is correct
3 Correct 51 ms 94280 KB Output is correct
4 Correct 48 ms 94296 KB Output is correct
5 Correct 50 ms 94212 KB Output is correct
6 Correct 49 ms 94156 KB Output is correct
7 Correct 50 ms 94180 KB Output is correct
8 Correct 48 ms 94284 KB Output is correct
9 Correct 54 ms 94256 KB Output is correct
10 Correct 48 ms 94248 KB Output is correct
11 Correct 48 ms 94216 KB Output is correct
12 Correct 50 ms 94280 KB Output is correct
13 Correct 47 ms 94156 KB Output is correct
14 Correct 49 ms 94308 KB Output is correct
15 Correct 54 ms 94200 KB Output is correct
16 Correct 48 ms 94284 KB Output is correct
17 Correct 48 ms 94172 KB Output is correct
18 Correct 53 ms 94232 KB Output is correct
19 Correct 49 ms 94280 KB Output is correct
20 Correct 59 ms 94236 KB Output is correct
21 Correct 51 ms 94352 KB Output is correct
22 Correct 50 ms 94376 KB Output is correct
23 Correct 52 ms 94404 KB Output is correct
24 Correct 50 ms 94284 KB Output is correct
25 Correct 51 ms 94476 KB Output is correct
26 Correct 54 ms 94272 KB Output is correct
27 Correct 51 ms 94412 KB Output is correct
28 Correct 50 ms 94548 KB Output is correct
29 Correct 51 ms 94392 KB Output is correct
30 Correct 52 ms 94328 KB Output is correct
31 Correct 50 ms 94304 KB Output is correct
32 Correct 53 ms 94368 KB Output is correct
33 Correct 52 ms 94400 KB Output is correct
34 Correct 54 ms 94388 KB Output is correct
35 Correct 51 ms 94376 KB Output is correct
36 Correct 49 ms 94284 KB Output is correct
37 Correct 50 ms 94316 KB Output is correct
38 Correct 56 ms 94368 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 50 ms 94272 KB Output is correct
2 Correct 49 ms 94248 KB Output is correct
3 Correct 51 ms 94280 KB Output is correct
4 Correct 48 ms 94296 KB Output is correct
5 Correct 50 ms 94212 KB Output is correct
6 Correct 49 ms 94156 KB Output is correct
7 Correct 50 ms 94180 KB Output is correct
8 Correct 48 ms 94284 KB Output is correct
9 Correct 54 ms 94256 KB Output is correct
10 Correct 48 ms 94248 KB Output is correct
11 Correct 48 ms 94216 KB Output is correct
12 Correct 50 ms 94280 KB Output is correct
13 Correct 47 ms 94156 KB Output is correct
14 Correct 49 ms 94308 KB Output is correct
15 Correct 54 ms 94200 KB Output is correct
16 Correct 48 ms 94284 KB Output is correct
17 Correct 48 ms 94172 KB Output is correct
18 Correct 53 ms 94232 KB Output is correct
19 Correct 396 ms 108052 KB Output is correct
20 Correct 398 ms 107976 KB Output is correct
21 Correct 384 ms 107952 KB Output is correct
22 Correct 349 ms 107084 KB Output is correct
23 Correct 373 ms 109480 KB Output is correct
24 Correct 219 ms 106916 KB Output is correct
25 Correct 382 ms 114096 KB Output is correct
26 Correct 304 ms 114312 KB Output is correct
27 Correct 354 ms 119172 KB Output is correct
28 Correct 933 ms 134920 KB Output is correct
29 Correct 985 ms 134848 KB Output is correct
30 Correct 361 ms 119368 KB Output is correct
31 Correct 347 ms 119220 KB Output is correct
32 Correct 506 ms 119116 KB Output is correct
33 Correct 672 ms 122876 KB Output is correct
34 Correct 424 ms 122048 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 50 ms 94272 KB Output is correct
2 Correct 49 ms 94248 KB Output is correct
3 Correct 51 ms 94280 KB Output is correct
4 Correct 48 ms 94296 KB Output is correct
5 Correct 50 ms 94212 KB Output is correct
6 Correct 49 ms 94156 KB Output is correct
7 Correct 50 ms 94180 KB Output is correct
8 Correct 48 ms 94284 KB Output is correct
9 Correct 54 ms 94256 KB Output is correct
10 Correct 48 ms 94248 KB Output is correct
11 Correct 48 ms 94216 KB Output is correct
12 Correct 50 ms 94280 KB Output is correct
13 Correct 47 ms 94156 KB Output is correct
14 Correct 49 ms 94308 KB Output is correct
15 Correct 54 ms 94200 KB Output is correct
16 Correct 48 ms 94284 KB Output is correct
17 Correct 48 ms 94172 KB Output is correct
18 Correct 53 ms 94232 KB Output is correct
19 Correct 49 ms 94280 KB Output is correct
20 Correct 59 ms 94236 KB Output is correct
21 Correct 51 ms 94352 KB Output is correct
22 Correct 50 ms 94376 KB Output is correct
23 Correct 52 ms 94404 KB Output is correct
24 Correct 50 ms 94284 KB Output is correct
25 Correct 51 ms 94476 KB Output is correct
26 Correct 54 ms 94272 KB Output is correct
27 Correct 51 ms 94412 KB Output is correct
28 Correct 50 ms 94548 KB Output is correct
29 Correct 51 ms 94392 KB Output is correct
30 Correct 52 ms 94328 KB Output is correct
31 Correct 50 ms 94304 KB Output is correct
32 Correct 53 ms 94368 KB Output is correct
33 Correct 52 ms 94400 KB Output is correct
34 Correct 54 ms 94388 KB Output is correct
35 Correct 51 ms 94376 KB Output is correct
36 Correct 49 ms 94284 KB Output is correct
37 Correct 50 ms 94316 KB Output is correct
38 Correct 56 ms 94368 KB Output is correct
39 Correct 396 ms 108052 KB Output is correct
40 Correct 398 ms 107976 KB Output is correct
41 Correct 384 ms 107952 KB Output is correct
42 Correct 349 ms 107084 KB Output is correct
43 Correct 373 ms 109480 KB Output is correct
44 Correct 219 ms 106916 KB Output is correct
45 Correct 382 ms 114096 KB Output is correct
46 Correct 304 ms 114312 KB Output is correct
47 Correct 354 ms 119172 KB Output is correct
48 Correct 933 ms 134920 KB Output is correct
49 Correct 985 ms 134848 KB Output is correct
50 Correct 361 ms 119368 KB Output is correct
51 Correct 347 ms 119220 KB Output is correct
52 Correct 506 ms 119116 KB Output is correct
53 Correct 672 ms 122876 KB Output is correct
54 Correct 424 ms 122048 KB Output is correct
55 Correct 63 ms 95432 KB Output is correct
56 Correct 69 ms 95564 KB Output is correct
57 Correct 360 ms 109600 KB Output is correct
58 Correct 111 ms 109492 KB Output is correct
59 Correct 229 ms 114300 KB Output is correct
60 Correct 953 ms 135304 KB Output is correct
61 Correct 346 ms 119332 KB Output is correct
62 Correct 348 ms 119244 KB Output is correct
63 Correct 497 ms 119116 KB Output is correct
64 Correct 993 ms 122632 KB Output is correct
65 Correct 450 ms 119972 KB Output is correct
66 Correct 851 ms 134684 KB Output is correct
67 Correct 303 ms 124756 KB Output is correct
68 Correct 470 ms 118516 KB Output is correct
69 Correct 477 ms 118724 KB Output is correct
70 Correct 458 ms 117368 KB Output is correct