답안 #895169

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
895169 2023-12-29T14:04:28 Z anton 경주 (Race) (IOI11_race) C++17
100 / 100
363 ms 68704 KB
#include "race.h"
#include<bits/stdc++.h>

using namespace std;
#define ll long long
#define pll pair<ll,ll>
const ll INF = 1e18;

struct VSet{
  map<ll, ll> us;
  ll d= 0;
  ll d2 = 0;

  bool is_in(ll v){
    return (us.find(v-d)!=us.end());
  }

  ll min_len(ll v){
    auto it =us.find(v-d);
    if(it!=us.end()){
      //cout<<it->second + d2<<endl;
      return it->second + d2;
    }
    else{
      return INF;
    }
  }

  void add(pll v){
    //cout<<"adding "<<v.first<<" "<<v.second<<endl;
    if(min_len(v.first)>v.second){
      us[v.first-d] = v.second-d2;
      //cout<<"passed "<<us[v.first-d]<<endl;
    }
  }

  void display(){
    for(auto e: us){
      //cout<<e.first+d<<" "<<e.second+d2<<endl;
    }
    //cout<<endl;
  }
};

ll res= INF;
int k;

void merge(VSet& a, VSet& b){
  if(a.us.size()<b.us.size()){
    swap(a.us,b.us);
    swap(a.d, b.d);
    swap(a.d2, b.d2);
  }

  for(auto e: b.us){
    res = min(res, e.second +b.d2 + a.min_len(k-(e.first+b.d)));
  }

  for(auto e: b.us){
    a.add(pll(e.first+b.d, e.second + b.d2));
  }

  //cout<<"a size "<<a.us.size()<<endl;
}

vector<vector<pll>> ch;

VSet dfs(int u, int anc){
  VSet cur;
  cur.add(pll(0, 0));
  for(auto e: ch[u]){
    if(e.first!=anc){
      VSet rh = dfs(e.first, u);
      rh.d += e.second;
      rh.d2 ++;

      merge(cur, rh);
    }
  }
  //cout<<"dfs "<<u<<endl;
  cur.display();
  return cur;
}

int best_path(int N, int K, int H[][2], int L[])
{
  ch.resize(N);
  k = K;
  for(int i = 0; i<N-1; i++){
    ch[H[i][0]].push_back(pll(H[i][1], L[i]));
    ch[H[i][1]].push_back(pll(H[i][0], L[i]));
  }

  dfs(0, -1);

  if(res==INF){
    return -1;
  }
  return res;
}

Compilation message

race.cpp: In member function 'void VSet::display()':
race.cpp:38:14: warning: variable 'e' set but not used [-Wunused-but-set-variable]
   38 |     for(auto e: us){
      |              ^
# 결과 실행 시간 메모리 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 2408 KB Output is correct
5 Correct 1 ms 2396 KB Output is correct
6 Correct 1 ms 2396 KB Output is correct
7 Correct 1 ms 2396 KB Output is correct
8 Correct 1 ms 2396 KB Output is correct
9 Correct 1 ms 2396 KB Output is correct
10 Correct 1 ms 2396 KB Output is correct
11 Correct 1 ms 2396 KB Output is correct
12 Correct 1 ms 2392 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 2396 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 2396 KB Output is correct
# 결과 실행 시간 메모리 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 2408 KB Output is correct
5 Correct 1 ms 2396 KB Output is correct
6 Correct 1 ms 2396 KB Output is correct
7 Correct 1 ms 2396 KB Output is correct
8 Correct 1 ms 2396 KB Output is correct
9 Correct 1 ms 2396 KB Output is correct
10 Correct 1 ms 2396 KB Output is correct
11 Correct 1 ms 2396 KB Output is correct
12 Correct 1 ms 2392 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 2396 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 2396 KB Output is correct
19 Correct 1 ms 2392 KB Output is correct
20 Correct 1 ms 2392 KB Output is correct
21 Correct 2 ms 2396 KB Output is correct
22 Correct 2 ms 2652 KB Output is correct
23 Correct 2 ms 2652 KB Output is correct
24 Correct 1 ms 2652 KB Output is correct
25 Correct 2 ms 2652 KB Output is correct
26 Correct 2 ms 2648 KB Output is correct
27 Correct 2 ms 2396 KB Output is correct
28 Correct 2 ms 2652 KB Output is correct
29 Correct 2 ms 2504 KB Output is correct
30 Correct 2 ms 2652 KB Output is correct
31 Correct 2 ms 2664 KB Output is correct
32 Correct 1 ms 2664 KB Output is correct
33 Correct 1 ms 2512 KB Output is correct
34 Correct 1 ms 2664 KB Output is correct
35 Correct 2 ms 2664 KB Output is correct
36 Correct 1 ms 2664 KB Output is correct
37 Correct 1 ms 2664 KB Output is correct
38 Correct 1 ms 2664 KB Output is correct
# 결과 실행 시간 메모리 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 2408 KB Output is correct
5 Correct 1 ms 2396 KB Output is correct
6 Correct 1 ms 2396 KB Output is correct
7 Correct 1 ms 2396 KB Output is correct
8 Correct 1 ms 2396 KB Output is correct
9 Correct 1 ms 2396 KB Output is correct
10 Correct 1 ms 2396 KB Output is correct
11 Correct 1 ms 2396 KB Output is correct
12 Correct 1 ms 2392 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 2396 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 2396 KB Output is correct
19 Correct 81 ms 13480 KB Output is correct
20 Correct 70 ms 13532 KB Output is correct
21 Correct 68 ms 13592 KB Output is correct
22 Correct 82 ms 13404 KB Output is correct
23 Correct 100 ms 14228 KB Output is correct
24 Correct 75 ms 13112 KB Output is correct
25 Correct 64 ms 25660 KB Output is correct
26 Correct 52 ms 36512 KB Output is correct
27 Correct 130 ms 23124 KB Output is correct
28 Correct 196 ms 68704 KB Output is correct
29 Correct 183 ms 67024 KB Output is correct
30 Correct 125 ms 23348 KB Output is correct
31 Correct 119 ms 23340 KB Output is correct
32 Correct 150 ms 23504 KB Output is correct
33 Correct 157 ms 22688 KB Output is correct
34 Correct 278 ms 36036 KB Output is correct
# 결과 실행 시간 메모리 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 2408 KB Output is correct
5 Correct 1 ms 2396 KB Output is correct
6 Correct 1 ms 2396 KB Output is correct
7 Correct 1 ms 2396 KB Output is correct
8 Correct 1 ms 2396 KB Output is correct
9 Correct 1 ms 2396 KB Output is correct
10 Correct 1 ms 2396 KB Output is correct
11 Correct 1 ms 2396 KB Output is correct
12 Correct 1 ms 2392 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 2396 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 2396 KB Output is correct
19 Correct 1 ms 2392 KB Output is correct
20 Correct 1 ms 2392 KB Output is correct
21 Correct 2 ms 2396 KB Output is correct
22 Correct 2 ms 2652 KB Output is correct
23 Correct 2 ms 2652 KB Output is correct
24 Correct 1 ms 2652 KB Output is correct
25 Correct 2 ms 2652 KB Output is correct
26 Correct 2 ms 2648 KB Output is correct
27 Correct 2 ms 2396 KB Output is correct
28 Correct 2 ms 2652 KB Output is correct
29 Correct 2 ms 2504 KB Output is correct
30 Correct 2 ms 2652 KB Output is correct
31 Correct 2 ms 2664 KB Output is correct
32 Correct 1 ms 2664 KB Output is correct
33 Correct 1 ms 2512 KB Output is correct
34 Correct 1 ms 2664 KB Output is correct
35 Correct 2 ms 2664 KB Output is correct
36 Correct 1 ms 2664 KB Output is correct
37 Correct 1 ms 2664 KB Output is correct
38 Correct 1 ms 2664 KB Output is correct
39 Correct 81 ms 13480 KB Output is correct
40 Correct 70 ms 13532 KB Output is correct
41 Correct 68 ms 13592 KB Output is correct
42 Correct 82 ms 13404 KB Output is correct
43 Correct 100 ms 14228 KB Output is correct
44 Correct 75 ms 13112 KB Output is correct
45 Correct 64 ms 25660 KB Output is correct
46 Correct 52 ms 36512 KB Output is correct
47 Correct 130 ms 23124 KB Output is correct
48 Correct 196 ms 68704 KB Output is correct
49 Correct 183 ms 67024 KB Output is correct
50 Correct 125 ms 23348 KB Output is correct
51 Correct 119 ms 23340 KB Output is correct
52 Correct 150 ms 23504 KB Output is correct
53 Correct 157 ms 22688 KB Output is correct
54 Correct 278 ms 36036 KB Output is correct
55 Correct 14 ms 3676 KB Output is correct
56 Correct 6 ms 3420 KB Output is correct
57 Correct 54 ms 13748 KB Output is correct
58 Correct 33 ms 12740 KB Output is correct
59 Correct 88 ms 36512 KB Output is correct
60 Correct 181 ms 67408 KB Output is correct
61 Correct 162 ms 25352 KB Output is correct
62 Correct 106 ms 23244 KB Output is correct
63 Correct 142 ms 23496 KB Output is correct
64 Correct 363 ms 31492 KB Output is correct
65 Correct 348 ms 36100 KB Output is correct
66 Correct 197 ms 63424 KB Output is correct
67 Correct 99 ms 23532 KB Output is correct
68 Correct 242 ms 33868 KB Output is correct
69 Correct 248 ms 38140 KB Output is correct
70 Correct 246 ms 32552 KB Output is correct