답안 #833851

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
833851 2023-08-22T09:02:51 Z algorithm16 경주 (Race) (IOI11_race) C++14
100 / 100
338 ms 63492 KB
#include<iostream>
#include<vector>
#include<set>
#include<algorithm>
#include "race.h"
using namespace std;
typedef long long int llint;
vector <pair<int,llint> > v[200005];
set <pair<llint,llint> > s[200005];
llint k1,mn=1e9,h[25][2],l[25];
void f(int x,int y,llint dd,llint ll) {
	if(s[x].size()<s[y].size()) swap(s[x],s[y]);
	for(set <pair<llint,llint> >::iterator it=s[y].begin();it!=s[y].end();it++) {
		llint l=(*it).first,d=(*it).second;
		l-=ll;
		d-=dd;
		set <pair<llint,llint> >::iterator it2=s[x].lower_bound(make_pair(k1-l+ll,-1LL));
		if(it2!=s[x].end() && (*it2).first==k1-l+ll) mn=min(mn,d+(*it2).second-dd);
	}
	for(set <pair<llint,llint> >::iterator it=s[y].begin();it!=s[y].end();) {
		llint l=(*it).first,d=(*it).second;
		l-=ll;
		d-=dd;
		set <pair<llint,llint> >::iterator it2=s[x].lower_bound(make_pair(l+ll,-1LL));
		if(it2==s[x].end() || (*it2).first!=l+ll) s[x].insert((*it));
		else if((*it2).second>(*it).second) {
			s[x].erase(it2);
			s[x].insert((*it));
		}
		it=s[y].erase(it);
	}
}
void dfs(int x,int p,llint d,llint l) {
	s[x].insert(make_pair(l,d));
	for(int i=0;i<v[x].size();i++) {
		if(v[x][i].first==p) continue;
		dfs(v[x][i].first,x,d+1,l+v[x][i].second);
		f(x,v[x][i].first,d,l);
	}
}
int best_path(int n,int k,int h[][2],int l[])
{
	if(!k) return 0;
	k1=k;
	for(int i=0;i<n-1;i++) {
		v[h[i][0]].push_back(make_pair(h[i][1],l[i]));
		v[h[i][1]].push_back(make_pair(h[i][0],l[i]));
	}
	dfs(0,0,0,0);
	if(mn==1e9) mn=-1;
	return mn;
}
/*int main()
{
	int n,k;
	cin >> n >> k;
	for(int i=0;i<n-1;i++) {
		int a,b,l1;
		cin >> a >> b >> l1;
		h[i][0]=a;
		h[i][1]=b;
		l[i]=l1;
	}
	cout << best_path(n,k);
}
*/

Compilation message

race.cpp: In function 'void dfs(int, int, llint, llint)':
race.cpp:35:15: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   35 |  for(int i=0;i<v[x].size();i++) {
      |              ~^~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 7 ms 14420 KB Output is correct
2 Correct 7 ms 14400 KB Output is correct
3 Correct 7 ms 14424 KB Output is correct
4 Correct 7 ms 14420 KB Output is correct
5 Correct 7 ms 14420 KB Output is correct
6 Correct 9 ms 14420 KB Output is correct
7 Correct 8 ms 14440 KB Output is correct
8 Correct 8 ms 14420 KB Output is correct
9 Correct 7 ms 14400 KB Output is correct
10 Correct 8 ms 14420 KB Output is correct
11 Correct 8 ms 14420 KB Output is correct
12 Correct 7 ms 14420 KB Output is correct
13 Correct 7 ms 14420 KB Output is correct
14 Correct 7 ms 14420 KB Output is correct
15 Correct 7 ms 14420 KB Output is correct
16 Correct 7 ms 14420 KB Output is correct
17 Correct 7 ms 14420 KB Output is correct
18 Correct 7 ms 14420 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 7 ms 14420 KB Output is correct
2 Correct 7 ms 14400 KB Output is correct
3 Correct 7 ms 14424 KB Output is correct
4 Correct 7 ms 14420 KB Output is correct
5 Correct 7 ms 14420 KB Output is correct
6 Correct 9 ms 14420 KB Output is correct
7 Correct 8 ms 14440 KB Output is correct
8 Correct 8 ms 14420 KB Output is correct
9 Correct 7 ms 14400 KB Output is correct
10 Correct 8 ms 14420 KB Output is correct
11 Correct 8 ms 14420 KB Output is correct
12 Correct 7 ms 14420 KB Output is correct
13 Correct 7 ms 14420 KB Output is correct
14 Correct 7 ms 14420 KB Output is correct
15 Correct 7 ms 14420 KB Output is correct
16 Correct 7 ms 14420 KB Output is correct
17 Correct 7 ms 14420 KB Output is correct
18 Correct 7 ms 14420 KB Output is correct
19 Correct 10 ms 14340 KB Output is correct
20 Correct 7 ms 14420 KB Output is correct
21 Correct 8 ms 14420 KB Output is correct
22 Correct 8 ms 14540 KB Output is correct
23 Correct 10 ms 14548 KB Output is correct
24 Correct 9 ms 14432 KB Output is correct
25 Correct 11 ms 14548 KB Output is correct
26 Correct 9 ms 14420 KB Output is correct
27 Correct 8 ms 14420 KB Output is correct
28 Correct 8 ms 14420 KB Output is correct
29 Correct 9 ms 14548 KB Output is correct
30 Correct 8 ms 14420 KB Output is correct
31 Correct 9 ms 14540 KB Output is correct
32 Correct 9 ms 14420 KB Output is correct
33 Correct 8 ms 14420 KB Output is correct
34 Correct 8 ms 14540 KB Output is correct
35 Correct 8 ms 14548 KB Output is correct
36 Correct 7 ms 14548 KB Output is correct
37 Correct 8 ms 14420 KB Output is correct
38 Correct 8 ms 14420 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 7 ms 14420 KB Output is correct
2 Correct 7 ms 14400 KB Output is correct
3 Correct 7 ms 14424 KB Output is correct
4 Correct 7 ms 14420 KB Output is correct
5 Correct 7 ms 14420 KB Output is correct
6 Correct 9 ms 14420 KB Output is correct
7 Correct 8 ms 14440 KB Output is correct
8 Correct 8 ms 14420 KB Output is correct
9 Correct 7 ms 14400 KB Output is correct
10 Correct 8 ms 14420 KB Output is correct
11 Correct 8 ms 14420 KB Output is correct
12 Correct 7 ms 14420 KB Output is correct
13 Correct 7 ms 14420 KB Output is correct
14 Correct 7 ms 14420 KB Output is correct
15 Correct 7 ms 14420 KB Output is correct
16 Correct 7 ms 14420 KB Output is correct
17 Correct 7 ms 14420 KB Output is correct
18 Correct 7 ms 14420 KB Output is correct
19 Correct 83 ms 21988 KB Output is correct
20 Correct 98 ms 22104 KB Output is correct
21 Correct 82 ms 22000 KB Output is correct
22 Correct 125 ms 22020 KB Output is correct
23 Correct 108 ms 22860 KB Output is correct
24 Correct 84 ms 21816 KB Output is correct
25 Correct 72 ms 30896 KB Output is correct
26 Correct 54 ms 38732 KB Output is correct
27 Correct 130 ms 30652 KB Output is correct
28 Correct 227 ms 63492 KB Output is correct
29 Correct 224 ms 61900 KB Output is correct
30 Correct 132 ms 30540 KB Output is correct
31 Correct 128 ms 30544 KB Output is correct
32 Correct 158 ms 30804 KB Output is correct
33 Correct 188 ms 29900 KB Output is correct
34 Correct 259 ms 42096 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 7 ms 14420 KB Output is correct
2 Correct 7 ms 14400 KB Output is correct
3 Correct 7 ms 14424 KB Output is correct
4 Correct 7 ms 14420 KB Output is correct
5 Correct 7 ms 14420 KB Output is correct
6 Correct 9 ms 14420 KB Output is correct
7 Correct 8 ms 14440 KB Output is correct
8 Correct 8 ms 14420 KB Output is correct
9 Correct 7 ms 14400 KB Output is correct
10 Correct 8 ms 14420 KB Output is correct
11 Correct 8 ms 14420 KB Output is correct
12 Correct 7 ms 14420 KB Output is correct
13 Correct 7 ms 14420 KB Output is correct
14 Correct 7 ms 14420 KB Output is correct
15 Correct 7 ms 14420 KB Output is correct
16 Correct 7 ms 14420 KB Output is correct
17 Correct 7 ms 14420 KB Output is correct
18 Correct 7 ms 14420 KB Output is correct
19 Correct 10 ms 14340 KB Output is correct
20 Correct 7 ms 14420 KB Output is correct
21 Correct 8 ms 14420 KB Output is correct
22 Correct 8 ms 14540 KB Output is correct
23 Correct 10 ms 14548 KB Output is correct
24 Correct 9 ms 14432 KB Output is correct
25 Correct 11 ms 14548 KB Output is correct
26 Correct 9 ms 14420 KB Output is correct
27 Correct 8 ms 14420 KB Output is correct
28 Correct 8 ms 14420 KB Output is correct
29 Correct 9 ms 14548 KB Output is correct
30 Correct 8 ms 14420 KB Output is correct
31 Correct 9 ms 14540 KB Output is correct
32 Correct 9 ms 14420 KB Output is correct
33 Correct 8 ms 14420 KB Output is correct
34 Correct 8 ms 14540 KB Output is correct
35 Correct 8 ms 14548 KB Output is correct
36 Correct 7 ms 14548 KB Output is correct
37 Correct 8 ms 14420 KB Output is correct
38 Correct 8 ms 14420 KB Output is correct
39 Correct 83 ms 21988 KB Output is correct
40 Correct 98 ms 22104 KB Output is correct
41 Correct 82 ms 22000 KB Output is correct
42 Correct 125 ms 22020 KB Output is correct
43 Correct 108 ms 22860 KB Output is correct
44 Correct 84 ms 21816 KB Output is correct
45 Correct 72 ms 30896 KB Output is correct
46 Correct 54 ms 38732 KB Output is correct
47 Correct 130 ms 30652 KB Output is correct
48 Correct 227 ms 63492 KB Output is correct
49 Correct 224 ms 61900 KB Output is correct
50 Correct 132 ms 30540 KB Output is correct
51 Correct 128 ms 30544 KB Output is correct
52 Correct 158 ms 30804 KB Output is correct
53 Correct 188 ms 29900 KB Output is correct
54 Correct 259 ms 42096 KB Output is correct
55 Correct 17 ms 15568 KB Output is correct
56 Correct 12 ms 15060 KB Output is correct
57 Correct 52 ms 22388 KB Output is correct
58 Correct 42 ms 20292 KB Output is correct
59 Correct 70 ms 37604 KB Output is correct
60 Correct 221 ms 59468 KB Output is correct
61 Correct 153 ms 29388 KB Output is correct
62 Correct 129 ms 27660 KB Output is correct
63 Correct 163 ms 27868 KB Output is correct
64 Correct 332 ms 34620 KB Output is correct
65 Correct 338 ms 39376 KB Output is correct
66 Correct 238 ms 55116 KB Output is correct
67 Correct 105 ms 26372 KB Output is correct
68 Correct 243 ms 37592 KB Output is correct
69 Correct 270 ms 37576 KB Output is correct
70 Correct 240 ms 36580 KB Output is correct