답안 #586359

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
586359 2022-06-30T07:10:30 Z xynex 경주 (Race) (IOI11_race) C++17
100 / 100
392 ms 88044 KB
/**
  * Author: Tenjin
  * Created: 28.06.2022 14:48
  * Why am I so stupid? :c
  * Slishkom slab
**/

#include <bits/stdc++.h>
#include "race.h"
// #pragma GCC optimize("inline")
// #pragma GCC optimize("-fgcse,-fgcse-lm")
// #pragma GCC optimize("-ftree-pre,-ftree-vrp")
// #pragma GCC optimize("-ffast-math")
// #pragma GCC optimize("-fipa-sra")
// #pragma GCC optimize("-fpeephole2")
// #pragma GCC optimize("-fsched-spec")
// #pragma GCC optimize("Ofast,no-stack-protector")
// #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,avx2,tune=native")
// #pragma GCC optimize("unroll-loops")

using namespace std;

#define ll long long
#define dl double long
#define ull unsigned long long
#define pr pair
#define vt vector
#define ff first
#define ss second
#define mp make_pair
#define sz(a) (int)a.size()
#define pb push_back
#define pf push_front
#define popB pop_back
#define popF pop_front
#define bit_count __builtin_popcount
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define sp(x) fixed << setprecision(x)

template<typename T> T get_rand(T l, T r) {
  random_device rd;
  mt19937 gen(rd());
  return uniform_int_distribution<T>(l, r)(gen);
}
template<typename T> T lcm(T a, T b) { return a * (b / __gcd(a, b)); }

template<class A> void read(vt<A>& v);
template<class A, size_t S> void read(array<A, S>& a);
template<class T> void read(T& x) { cin >> x; }
void read(double& d) { string t; read(t); d = stod(t); }
void read(long double& d) { string t; read(t); d = stold(t); }
template<class H, class... T> void read(H& h, T&... t) { read(h); read(t...); }
template<class A> void read(vt<A>& x) { for (auto& a : x) read(a); }
template<class A, size_t S> void read(array<A, S>& x) { for (auto& a : x) read(a); }

string to_string(char c) { return string(1, c); }
string to_string(bool b) { return b ? "true" : "false"; }
string to_string(const char* s) { return string(s); }
string to_string(string s) { return s; }
string to_string(vt<bool> v) { string res; for (int i = 0; i < sz(v); ++i) res += char('0' + v[i]); return res; }
template<size_t S> string to_string(bitset<S> b) { string res; for (int i = 0; i < S; ++i) res += char('0' + b[i]); return res; }
template<class T> string to_string(T v) { bool f = 1; string res; for (auto x : v) { if (!f) res += ' '; f = 0; res += to_string(x); } return res; }

template<class A> void write(A x) { cout << to_string(x); }
template<class H, class... T> void write(const H& h, const T&... t) { write(h); write(t...); }

void print() { write("\n"); }
template<class H, class... T> void print(const H& h, const T&... t) { write(h); if (sizeof...(t)) write(' '); print(t...); }

void freop(string s) {
  freopen((s + ".in").c_str(), "r", stdin);
  freopen((s + ".out").c_str(), "w", stdout);
}

const int MOD = 1e9 + 7;
const int N = 2e5 + 5;
const ll INF = 9e18;
const int M = 3e3 + 5;
const dl pi = acos(-1);
const dl eps = 1e-12;
const int sq = 700;

int dx[] = {-1, 0, 1, 0};
int dy[] = {0, -1, 0, 1};
/* ll vs int*/


vt<pr<int, int> > g[N];
int n, k, G[N][2], l[N];
int ans;
set<pr<int, int> > d[N];
void dfs(int v, int p = 0, int dist = 0, int dep = 0) {
  d[v].insert({dist, dep});
  for(auto to : g[v]) {
    if(to.ff == p) continue;
    dfs(to.ff, v, dist + to.ss, dep + 1);
    if(sz(d[v]) < sz(d[to.ff])) swap(d[v], d[to.ff]);
    for(auto ind : d[to.ff]) {
      ll need = k - ind.ff + dist * 2;
      auto whr = d[v].lower_bound({need, -1});
      if(whr == d[v].end()) continue;
      auto cur = *whr;
      if(cur.ff != need) continue;
      ans = min(ans, cur.ss + ind.ss - dep * 2);
    }
    for(auto ind : d[to.ff]) d[v].insert(ind);
  }
}
int best_path(int n, int w, int G[][2], int l[]) {
  k = w;
  for(int i = 0; i < n - 1; ++i) {
    g[G[i][0]].pb({G[i][1], l[i]});
    g[G[i][1]].pb({G[i][0], l[i]});
  }
  ans = MOD;
  dfs(0);
  if(ans == MOD) ans = -1;
  return ans;
}

Compilation message

race.cpp: In function 'void freop(std::string)':
race.cpp:72:10: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   72 |   freopen((s + ".in").c_str(), "r", stdin);
      |   ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
race.cpp:73:10: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   73 |   freopen((s + ".out").c_str(), "w", stdout);
      |   ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 7 ms 14420 KB Output is correct
2 Correct 7 ms 14420 KB Output is correct
3 Correct 7 ms 14420 KB Output is correct
4 Correct 6 ms 14420 KB Output is correct
5 Correct 7 ms 14420 KB Output is correct
6 Correct 7 ms 14420 KB Output is correct
7 Correct 8 ms 14412 KB Output is correct
8 Correct 7 ms 14420 KB Output is correct
9 Correct 7 ms 14420 KB Output is correct
10 Correct 8 ms 14444 KB Output is correct
11 Correct 7 ms 14420 KB Output is correct
12 Correct 8 ms 14420 KB Output is correct
13 Correct 8 ms 14404 KB Output is correct
14 Correct 9 ms 14408 KB Output is correct
15 Correct 7 ms 14420 KB Output is correct
16 Correct 8 ms 14416 KB Output is correct
17 Correct 9 ms 14444 KB Output is correct
18 Correct 9 ms 14420 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 7 ms 14420 KB Output is correct
2 Correct 7 ms 14420 KB Output is correct
3 Correct 7 ms 14420 KB Output is correct
4 Correct 6 ms 14420 KB Output is correct
5 Correct 7 ms 14420 KB Output is correct
6 Correct 7 ms 14420 KB Output is correct
7 Correct 8 ms 14412 KB Output is correct
8 Correct 7 ms 14420 KB Output is correct
9 Correct 7 ms 14420 KB Output is correct
10 Correct 8 ms 14444 KB Output is correct
11 Correct 7 ms 14420 KB Output is correct
12 Correct 8 ms 14420 KB Output is correct
13 Correct 8 ms 14404 KB Output is correct
14 Correct 9 ms 14408 KB Output is correct
15 Correct 7 ms 14420 KB Output is correct
16 Correct 8 ms 14416 KB Output is correct
17 Correct 9 ms 14444 KB Output is correct
18 Correct 9 ms 14420 KB Output is correct
19 Correct 7 ms 14420 KB Output is correct
20 Correct 7 ms 14400 KB Output is correct
21 Correct 8 ms 14548 KB Output is correct
22 Correct 10 ms 14548 KB Output is correct
23 Correct 8 ms 14600 KB Output is correct
24 Correct 8 ms 14592 KB Output is correct
25 Correct 10 ms 14548 KB Output is correct
26 Correct 9 ms 14540 KB Output is correct
27 Correct 8 ms 14424 KB Output is correct
28 Correct 8 ms 14564 KB Output is correct
29 Correct 8 ms 14548 KB Output is correct
30 Correct 9 ms 14548 KB Output is correct
31 Correct 8 ms 14548 KB Output is correct
32 Correct 8 ms 14548 KB Output is correct
33 Correct 8 ms 14548 KB Output is correct
34 Correct 8 ms 14612 KB Output is correct
35 Correct 8 ms 14548 KB Output is correct
36 Correct 8 ms 14548 KB Output is correct
37 Correct 8 ms 14548 KB Output is correct
38 Correct 8 ms 14612 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 7 ms 14420 KB Output is correct
2 Correct 7 ms 14420 KB Output is correct
3 Correct 7 ms 14420 KB Output is correct
4 Correct 6 ms 14420 KB Output is correct
5 Correct 7 ms 14420 KB Output is correct
6 Correct 7 ms 14420 KB Output is correct
7 Correct 8 ms 14412 KB Output is correct
8 Correct 7 ms 14420 KB Output is correct
9 Correct 7 ms 14420 KB Output is correct
10 Correct 8 ms 14444 KB Output is correct
11 Correct 7 ms 14420 KB Output is correct
12 Correct 8 ms 14420 KB Output is correct
13 Correct 8 ms 14404 KB Output is correct
14 Correct 9 ms 14408 KB Output is correct
15 Correct 7 ms 14420 KB Output is correct
16 Correct 8 ms 14416 KB Output is correct
17 Correct 9 ms 14444 KB Output is correct
18 Correct 9 ms 14420 KB Output is correct
19 Correct 127 ms 34608 KB Output is correct
20 Correct 132 ms 34676 KB Output is correct
21 Correct 133 ms 34084 KB Output is correct
22 Correct 128 ms 32952 KB Output is correct
23 Correct 151 ms 43768 KB Output is correct
24 Correct 114 ms 33832 KB Output is correct
25 Correct 115 ms 37720 KB Output is correct
26 Correct 76 ms 42108 KB Output is correct
27 Correct 203 ms 40964 KB Output is correct
28 Correct 255 ms 72976 KB Output is correct
29 Correct 256 ms 71624 KB Output is correct
30 Correct 214 ms 43912 KB Output is correct
31 Correct 197 ms 43864 KB Output is correct
32 Correct 244 ms 43936 KB Output is correct
33 Correct 195 ms 45012 KB Output is correct
34 Correct 310 ms 69848 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 7 ms 14420 KB Output is correct
2 Correct 7 ms 14420 KB Output is correct
3 Correct 7 ms 14420 KB Output is correct
4 Correct 6 ms 14420 KB Output is correct
5 Correct 7 ms 14420 KB Output is correct
6 Correct 7 ms 14420 KB Output is correct
7 Correct 8 ms 14412 KB Output is correct
8 Correct 7 ms 14420 KB Output is correct
9 Correct 7 ms 14420 KB Output is correct
10 Correct 8 ms 14444 KB Output is correct
11 Correct 7 ms 14420 KB Output is correct
12 Correct 8 ms 14420 KB Output is correct
13 Correct 8 ms 14404 KB Output is correct
14 Correct 9 ms 14408 KB Output is correct
15 Correct 7 ms 14420 KB Output is correct
16 Correct 8 ms 14416 KB Output is correct
17 Correct 9 ms 14444 KB Output is correct
18 Correct 9 ms 14420 KB Output is correct
19 Correct 7 ms 14420 KB Output is correct
20 Correct 7 ms 14400 KB Output is correct
21 Correct 8 ms 14548 KB Output is correct
22 Correct 10 ms 14548 KB Output is correct
23 Correct 8 ms 14600 KB Output is correct
24 Correct 8 ms 14592 KB Output is correct
25 Correct 10 ms 14548 KB Output is correct
26 Correct 9 ms 14540 KB Output is correct
27 Correct 8 ms 14424 KB Output is correct
28 Correct 8 ms 14564 KB Output is correct
29 Correct 8 ms 14548 KB Output is correct
30 Correct 9 ms 14548 KB Output is correct
31 Correct 8 ms 14548 KB Output is correct
32 Correct 8 ms 14548 KB Output is correct
33 Correct 8 ms 14548 KB Output is correct
34 Correct 8 ms 14612 KB Output is correct
35 Correct 8 ms 14548 KB Output is correct
36 Correct 8 ms 14548 KB Output is correct
37 Correct 8 ms 14548 KB Output is correct
38 Correct 8 ms 14612 KB Output is correct
39 Correct 127 ms 34608 KB Output is correct
40 Correct 132 ms 34676 KB Output is correct
41 Correct 133 ms 34084 KB Output is correct
42 Correct 128 ms 32952 KB Output is correct
43 Correct 151 ms 43768 KB Output is correct
44 Correct 114 ms 33832 KB Output is correct
45 Correct 115 ms 37720 KB Output is correct
46 Correct 76 ms 42108 KB Output is correct
47 Correct 203 ms 40964 KB Output is correct
48 Correct 255 ms 72976 KB Output is correct
49 Correct 256 ms 71624 KB Output is correct
50 Correct 214 ms 43912 KB Output is correct
51 Correct 197 ms 43864 KB Output is correct
52 Correct 244 ms 43936 KB Output is correct
53 Correct 195 ms 45012 KB Output is correct
54 Correct 310 ms 69848 KB Output is correct
55 Correct 19 ms 17108 KB Output is correct
56 Correct 15 ms 16160 KB Output is correct
57 Correct 76 ms 31944 KB Output is correct
58 Correct 49 ms 25184 KB Output is correct
59 Correct 73 ms 43492 KB Output is correct
60 Correct 243 ms 71996 KB Output is correct
61 Correct 221 ms 48224 KB Output is correct
62 Correct 178 ms 43976 KB Output is correct
63 Correct 245 ms 44080 KB Output is correct
64 Correct 392 ms 88044 KB Output is correct
65 Correct 387 ms 81988 KB Output is correct
66 Correct 258 ms 68656 KB Output is correct
67 Correct 152 ms 37560 KB Output is correct
68 Correct 313 ms 55880 KB Output is correct
69 Correct 376 ms 59972 KB Output is correct
70 Correct 311 ms 54168 KB Output is correct