답안 #832910

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
832910 2023-08-21T16:36:27 Z tolbi Fireworks (APIO16_fireworks) C++17
7 / 100
1 ms 340 KB
#include <bits/stdc++.h>
#define int long long
using namespace std;
#define deci(x) int x;cin>>x;
#define INF LONG_LONG_MAX
const int MOD = 1e9+7;
int32_t main(){
	deci(n);deci(m);
	vector<vector<pair<int,int>>> tree(n+m);
	vector<vector<int>> arr(n+m);
	for (int i = 1; i < n+m; ++i)
	{
		int u = i+1;
		deci(v);deci(w);
		tree[u-1].push_back({v-1,w});
		tree[v-1].push_back({u-1,w});
		arr[u-1].push_back(v-1);
		arr[v-1].push_back(u-1);
	}
	auto solve = [&](int x){
		int ans = 0;
		auto dfs = [&](int node, int lnode, int crr, auto dfs)->int{
			if (node>=n){
				return crr;
			}
			vector<int> hueh;
			for (int i = 0; i < tree[node].size(); i++){
				if (tree[node][i].first==lnode) continue;
				hueh.push_back(dfs(tree[node][i].first,node,tree[node][i].second+crr,dfs));
			}
			sort(hueh.begin(), hueh.end());
			int l = hueh[hueh.size()/2];
			int r = l;
			if (hueh.size()%2==0) r=hueh[hueh.size()/2+1];
			for (int i = 0; i < hueh.size(); i++){
				ans+=abs(hueh[i]-hueh[hueh.size()/2]);
			}
			if (r<x) return r;
			if (l>x) return l;
			return x;
		};
		dfs(0,-1,0,dfs);
		return ans;
	};
	int l = 0, r = INF;
	while (l<r){
		int mid = l+(r-l)/2;
		if (solve(mid)<=solve(mid+1)){
			r=mid;
		}
		else l = mid+1;
	}
	cout<<solve(l)<<endl;
}

Compilation message

fireworks.cpp: In lambda function:
fireworks.cpp:35:22: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   35 |    for (int i = 0; i < hueh.size(); i++){
      |                    ~~^~~~~~~~~~~~~
fireworks.cpp: In instantiation of 'main()::<lambda(long long int)>::<lambda(long long int, long long int, long long int, auto:23)> [with auto:23 = main()::<lambda(long long int)>::<lambda(long long int, long long int, long long int, auto:23)>]':
fireworks.cpp:42:18:   required from here
fireworks.cpp:27:22: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<std::pair<long long int, long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   27 |    for (int i = 0; i < tree[node].size(); i++){
      |                    ~~^~~~~~~~~~~~~~~~~~~
fireworks.cpp:35:22: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   35 |    for (int i = 0; i < hueh.size(); i++){
      |                    ~~^~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Incorrect 0 ms 212 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Incorrect 0 ms 212 KB Output isn't correct
12 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Incorrect 0 ms 212 KB Output isn't correct
12 Halted 0 ms 0 KB -