답안 #832903

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
832903 2023-08-21T16:29:59 Z tolbi Fireworks (APIO16_fireworks) C++17
0 / 100
2000 ms 212 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);
	}
	int ans = 0;
	auto dfs = [&](int node, int lnode, int crr, auto dfs)->pair<int,int>{
		if (node>=n){
			return {crr,crr};
		}
		vector<pair<int,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 mir = INF;
		int mal = 0;
		for (int i = 0; i < hueh.size(); i++){
			mir=min(mir,hueh[i].first);
			mal=max(mal,hueh[i].second);
		}
		int miva = INF;
		int l = mir, r = mir;
		for (int i = mir; i <= mal; i++){
			int crr = 0;
			for (int j = 0; j < hueh.size(); j++){
				if (hueh[j].first>i) crr+=hueh[j].first-i;
				else if (hueh[j].second<i) crr+=i-hueh[j].second;
			}
			if (crr<miva){
				miva=crr;
				l=i,r=i;
			}
			else if (crr==miva){
				r=i;
			}
		}
		ans+=miva;
		return {l,r};
	};
	dfs(0,-1,0,dfs);
	cout<<ans<<endl;
}

Compilation message

fireworks.cpp: In lambda function:
fireworks.cpp:33:21: 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]
   33 |   for (int i = 0; i < hueh.size(); i++){
      |                   ~~^~~~~~~~~~~~~
fireworks.cpp:41: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]
   41 |    for (int j = 0; j < hueh.size(); j++){
      |                    ~~^~~~~~~~~~~~~
fireworks.cpp: In instantiation of 'main()::<lambda(long long int, long long int, long long int, auto:23)> [with auto:23 = main()::<lambda(long long int, long long int, long long int, auto:23)>]':
fireworks.cpp:56:17:   required from here
fireworks.cpp:26:21: 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]
   26 |   for (int i = 0; i < tree[node].size(); i++){
      |                   ~~^~~~~~~~~~~~~~~~~~~
fireworks.cpp:33:21: 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]
   33 |   for (int i = 0; i < hueh.size(); i++){
      |                   ~~^~~~~~~~~~~~~
fireworks.cpp:41: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]
   41 |    for (int j = 0; j < hueh.size(); j++){
      |                    ~~^~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Execution timed out 2073 ms 212 KB Time limit exceeded
3 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 Incorrect 0 ms 212 KB Output isn't correct
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Execution timed out 2073 ms 212 KB Time limit exceeded
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Execution timed out 2073 ms 212 KB Time limit exceeded
3 Halted 0 ms 0 KB -