답안 #852465

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
852465 2023-09-21T20:29:13 Z midi 꿈 (IOI13_dreaming) C++14
40 / 100
115 ms 65536 KB
#include "dreaming.h"
#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
#define vc vector
typedef vc<ll> vcll;
#define pr pair
typedef pr<ll, ll> prll;
#define umap unordered_map

#define f0r(i,a,n) for (i=(a); i<(n); i++)
#define f1r(i,a,n) for (i=(a); i<=(n); i++)
#define r0f(i,n,a) for (i=(n); i>(a); i--)
#define r1f(i,n,a) for (i=(n); i>=(a); i--)

#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define in(s, x) ((s).find((x)) != (s).end())
#define all(x) (x).begin(), (x).end()
#define allrev(x) (x).rbegin(), (x).rend()

inline void maxa(ll &a, ll b) { if (a<b) a=b; }
inline void mina(ll &a, ll b) { if (a>b) a=b; }

#define INF (LLONG_MAX>>2ll)
#define mxN 100'010ll

ll n, m, l;
int *uar, *var, *war;
vc<vc<prll>> gr(mxN); // fi is w, se is v
vc<prll> par(mxN);
vc<vcll> from_tar(mxN); // .back() is for the parent
vc<umap<ll, ll>> nindex(mxN); // index of node in the gr, from_tar, excetera
vcll f;

inline void build_gr()
{
	ll i;
	f0r(i,0,m)
	{
		ll u, v, w;
		u=uar[i];
		v=var[i];
		w=war[i];

		nindex[u][v] = gr[u].size();
		nindex[v][u] = gr[v].size();
		gr[u].pb({w, v});
		gr[v].pb({w, u});
		from_tar[u].pb(-1);
		from_tar[v].pb(-1);
	}
}

vc<bool> seen(mxN, 0);
vcll whole(mxN); // whole

vcll comp; // comp for component

void dfs(ll u) // makes tree // good
{
	if (seen[u]) return;
	seen[u]=1;
	comp.pb(u);
	for (prll edge : gr[u])
	{
		ll v=edge.se;
		if (seen[v]) continue; // is par
		ll w=edge.fi;
		par[v]={w, u};
		dfs(v);
	}
}

ll calc_cnt=0;
ll clutch_cnt=0;

ll calc_whole(ll u)
{
	ll m=0; // max

	for (prll edge : gr[u])
	{
		ll v=edge.se;
		ll w = edge.fi;
		maxa(m, calc_whole(v) + w);
	}

	return whole[u]=m;
}

vc<umap<ll, ll>> max_except(mxN);

void build_except(ll u, vc<prll> &ar) // fi is node, se is max
{
	ll i;
	ll n=ar.size();

	/*
	printf("bulid_except of u: %lli\n", u);
	printf("ar: ");
	f0r(i,0,n) printf("{%lli, %lli} ", ar[i].se, ar[i].fi);
	printf("\n");
	*/

	vcll sma(n+10); // max, incl., sma[n]==0
	sma[n]=0;
	r1f(i,n-1, 0) sma[i]=max(sma[i+1], ar[i].fi);
	/*
	printf("sma: ");
	f0r(i,0,n) printf("%lli ", sma[i]);
	printf("\n");
	*/

	ll rm=0; // running max

	f0r(i,0,n)
	{
		max_except[u][ar[i].se] = max(rm, sma[i+1]);
		// printf("rm: %lli\n", rm);
		// printf("value of %lli: %lli\n", ar[i].se, max(rm, sma[i+1]));
		maxa(rm, ar[i].fi);
	}

	sma.clear();
}

void build_ar_root(ll u)
{
	vc<prll> ar;
	for (prll edge : gr[u])
	{
		ll v=edge.se;
		ll w=edge.fi;
		ar.pb({whole[v]+w, v});
	}

	build_except(u, ar);
	ar.clear();
}

ll root;
ll gm;

ll dfs_calc_real(ll u)
{
	ll m=whole[u]; // max
	if (u==root)
	{
		for (prll edge : gr[u])
		{
			ll v = edge.se;
			mina(gm, dfs_calc_real(v));
		}

		return m;
	}

	// u!=root
	
	vc<prll> ar;
	
	for (prll edge : gr[u])
	{
		ll v = edge.se;
		ll w = edge.fi;
		ar.pb({whole[v]+w, v});
	}
	ll p=par[u].se;
	ll w=par[u].fi;
	ll v = max_except[p][u];
	maxa(whole[u], w+v);
	ar.pb({w+v, p});
	m=whole[u];

	build_except(u, ar);
	ar.clear();

	for (prll edge : gr[u])
	{
		ll v = edge.se;
		mina(gm, dfs_calc_real(v));
	}

	return m;
}

inline void remake_gr()
{
	for (ll u : comp) for (prll &edge : gr[u])
		{
			ll v=edge.se;
			if (par[u].se==v)
			{
				edge=gr[u][gr[u].size()-1];
				gr[u].pop_back();
			}
		}
}

inline ll minmaxdist(ll u)
{
	comp.clear();
	root=u;
	par[root]={0, -1};
	dfs(u); // good
	remake_gr(); // bad
	// printf("comp.size: %lli\n", (ll)comp.size());
	
	calc_whole(u); // prob works
	build_ar_root(u);

	gm=INF;
	ll t = dfs_calc_real(u); // min
	mina(gm, t);

	// printf("m: %lli, on u: %lli\n", m, u);

	return gm;
}

inline void build_ar()
{
	ll u;
	f0r(u,0,n)
	{
		if (seen[u]) continue;
		// printf("WPAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA, u: %lli\n", u);
		f.pb(minmaxdist(u));
	}
}

inline ll value()
{
	ll z=f.size();
	ll m=-1; // max
	/*
	printf("z: %lli\n", z);
	printf("f: ");
	for (ll v : f) printf("%lli ", v);
	printf("\n");
	*/

	if (z==1) m = f[0];
	else if (z==2) m = f[0]+f[1]+l;
	else m = max(f[0]+f[1]+l, f[1]+f[2]+(2*l));

	ll u;
	f0r(u,0,n) maxa(m, whole[u]);
	return m;
}

int travelTime(int N, int M, int L, int A[], int B[], int T[])
{
	n=N;
	m=M;
	l=L;
	uar=A;
	var=B;
	war=T;

	build_gr();
	build_ar(); // slow
	sort(allrev(f));
	return value();
}
# 결과 실행 시간 메모리 Grader output
1 Runtime error 115 ms 65536 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 7 ms 18520 KB Output is correct
2 Correct 6 ms 18524 KB Output is correct
3 Correct 6 ms 18524 KB Output is correct
4 Correct 7 ms 18484 KB Output is correct
5 Correct 6 ms 18524 KB Output is correct
6 Correct 7 ms 18780 KB Output is correct
7 Correct 7 ms 18524 KB Output is correct
8 Correct 7 ms 18524 KB Output is correct
9 Correct 7 ms 18524 KB Output is correct
10 Correct 6 ms 18540 KB Output is correct
11 Correct 6 ms 18520 KB Output is correct
12 Correct 7 ms 18464 KB Output is correct
13 Correct 7 ms 18524 KB Output is correct
14 Correct 7 ms 18524 KB Output is correct
15 Correct 7 ms 18268 KB Output is correct
16 Correct 6 ms 18520 KB Output is correct
17 Correct 7 ms 18524 KB Output is correct
18 Correct 7 ms 18676 KB Output is correct
19 Correct 7 ms 18520 KB Output is correct
20 Correct 7 ms 18524 KB Output is correct
21 Correct 7 ms 18292 KB Output is correct
22 Correct 9 ms 18480 KB Output is correct
23 Correct 7 ms 18520 KB Output is correct
24 Correct 7 ms 18524 KB Output is correct
25 Correct 6 ms 18524 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Runtime error 115 ms 65536 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 62 ms 41104 KB Output is correct
2 Correct 66 ms 41396 KB Output is correct
3 Correct 66 ms 41012 KB Output is correct
4 Correct 65 ms 41212 KB Output is correct
5 Correct 65 ms 41172 KB Output is correct
6 Correct 69 ms 42932 KB Output is correct
7 Correct 67 ms 42208 KB Output is correct
8 Correct 62 ms 40628 KB Output is correct
9 Correct 64 ms 40652 KB Output is correct
10 Correct 65 ms 41904 KB Output is correct
11 Correct 6 ms 18264 KB Output is correct
12 Correct 12 ms 19668 KB Output is correct
13 Correct 14 ms 19712 KB Output is correct
14 Correct 12 ms 19692 KB Output is correct
15 Correct 14 ms 19964 KB Output is correct
16 Correct 11 ms 19684 KB Output is correct
17 Correct 12 ms 19412 KB Output is correct
18 Correct 13 ms 19924 KB Output is correct
19 Correct 13 ms 19692 KB Output is correct
20 Correct 6 ms 18268 KB Output is correct
21 Correct 7 ms 18268 KB Output is correct
22 Correct 6 ms 18524 KB Output is correct
23 Correct 12 ms 19692 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 7 ms 18520 KB Output is correct
2 Correct 6 ms 18524 KB Output is correct
3 Correct 6 ms 18524 KB Output is correct
4 Correct 7 ms 18484 KB Output is correct
5 Correct 6 ms 18524 KB Output is correct
6 Correct 7 ms 18780 KB Output is correct
7 Correct 7 ms 18524 KB Output is correct
8 Correct 7 ms 18524 KB Output is correct
9 Correct 7 ms 18524 KB Output is correct
10 Correct 6 ms 18540 KB Output is correct
11 Correct 6 ms 18520 KB Output is correct
12 Correct 7 ms 18464 KB Output is correct
13 Correct 7 ms 18524 KB Output is correct
14 Correct 7 ms 18524 KB Output is correct
15 Correct 7 ms 18268 KB Output is correct
16 Correct 6 ms 18520 KB Output is correct
17 Correct 7 ms 18524 KB Output is correct
18 Correct 7 ms 18676 KB Output is correct
19 Correct 7 ms 18520 KB Output is correct
20 Correct 7 ms 18524 KB Output is correct
21 Correct 7 ms 18292 KB Output is correct
22 Correct 9 ms 18480 KB Output is correct
23 Correct 7 ms 18520 KB Output is correct
24 Correct 7 ms 18524 KB Output is correct
25 Correct 6 ms 18524 KB Output is correct
26 Correct 7 ms 18776 KB Output is correct
27 Correct 10 ms 19292 KB Output is correct
28 Correct 9 ms 19548 KB Output is correct
29 Correct 8 ms 18780 KB Output is correct
30 Correct 8 ms 19264 KB Output is correct
31 Correct 10 ms 19548 KB Output is correct
32 Correct 7 ms 18868 KB Output is correct
33 Correct 8 ms 19292 KB Output is correct
34 Correct 9 ms 19800 KB Output is correct
35 Correct 7 ms 18268 KB Output is correct
36 Correct 8 ms 18484 KB Output is correct
37 Correct 6 ms 18520 KB Output is correct
38 Correct 6 ms 18524 KB Output is correct
39 Correct 7 ms 18524 KB Output is correct
40 Correct 6 ms 18268 KB Output is correct
41 Correct 7 ms 18268 KB Output is correct
42 Correct 6 ms 18524 KB Output is correct
43 Correct 7 ms 18352 KB Output is correct
44 Correct 7 ms 18520 KB Output is correct
45 Correct 7 ms 18524 KB Output is correct
46 Correct 6 ms 18524 KB Output is correct
47 Correct 6 ms 18488 KB Output is correct
48 Correct 6 ms 18328 KB Output is correct
49 Correct 7 ms 18524 KB Output is correct
50 Correct 7 ms 18372 KB Output is correct
51 Correct 6 ms 18524 KB Output is correct
52 Correct 6 ms 18268 KB Output is correct
53 Correct 6 ms 18348 KB Output is correct
54 Correct 11 ms 20056 KB Output is correct
55 Correct 9 ms 20056 KB Output is correct
56 Correct 9 ms 19292 KB Output is correct
57 Correct 7 ms 18780 KB Output is correct
58 Correct 9 ms 19840 KB Output is correct
59 Correct 10 ms 19804 KB Output is correct
60 Correct 9 ms 19036 KB Output is correct
61 Correct 8 ms 19036 KB Output is correct
62 Correct 9 ms 19804 KB Output is correct
63 Correct 10 ms 19804 KB Output is correct
64 Correct 7 ms 18524 KB Output is correct
65 Correct 8 ms 19292 KB Output is correct
66 Correct 10 ms 19804 KB Output is correct
67 Correct 9 ms 19784 KB Output is correct
68 Correct 9 ms 19548 KB Output is correct
69 Correct 9 ms 19552 KB Output is correct
70 Correct 7 ms 19036 KB Output is correct
71 Correct 8 ms 19020 KB Output is correct
72 Correct 9 ms 19804 KB Output is correct
73 Correct 11 ms 19772 KB Output is correct
74 Correct 10 ms 19804 KB Output is correct
75 Correct 9 ms 19804 KB Output is correct
76 Correct 10 ms 19780 KB Output is correct
77 Correct 11 ms 19804 KB Output is correct
78 Correct 8 ms 19036 KB Output is correct
79 Correct 7 ms 19036 KB Output is correct
80 Correct 7 ms 18772 KB Output is correct
81 Correct 6 ms 18452 KB Output is correct
82 Correct 9 ms 19776 KB Output is correct
83 Correct 11 ms 19548 KB Output is correct
84 Correct 8 ms 19012 KB Output is correct
85 Correct 7 ms 18524 KB Output is correct
86 Correct 8 ms 19292 KB Output is correct
87 Correct 10 ms 19804 KB Output is correct
88 Correct 8 ms 19288 KB Output is correct
89 Correct 9 ms 19220 KB Output is correct
90 Correct 8 ms 19032 KB Output is correct
91 Correct 8 ms 19032 KB Output is correct
92 Correct 9 ms 19544 KB Output is correct
93 Correct 9 ms 19292 KB Output is correct
94 Correct 8 ms 19464 KB Output is correct
95 Correct 9 ms 19548 KB Output is correct
96 Correct 9 ms 19544 KB Output is correct
97 Correct 9 ms 19512 KB Output is correct
98 Correct 9 ms 19552 KB Output is correct
99 Correct 10 ms 19828 KB Output is correct
100 Correct 9 ms 19556 KB Output is correct
101 Correct 9 ms 19556 KB Output is correct
102 Correct 8 ms 18528 KB Output is correct
103 Correct 6 ms 18532 KB Output is correct
104 Correct 7 ms 18524 KB Output is correct
105 Correct 6 ms 18396 KB Output is correct
106 Correct 6 ms 18520 KB Output is correct
107 Correct 8 ms 18556 KB Output is correct
108 Correct 7 ms 18536 KB Output is correct
109 Correct 7 ms 18784 KB Output is correct
110 Correct 8 ms 18484 KB Output is correct
111 Correct 7 ms 18524 KB Output is correct
112 Correct 7 ms 18412 KB Output is correct
113 Correct 7 ms 18776 KB Output is correct
114 Correct 9 ms 18780 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Runtime error 115 ms 65536 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -