답안 #1103500

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1103500 2024-10-21T04:39:05 Z ezzzay 나일강 (IOI24_nile) C++17
32 / 100
72 ms 13004 KB
#include<bits/stdc++.h>
using namespace std;
#define ff first
#define ss second
#define pb push_back
#define ll long long
const int N=3e5+5;
int par[N];
int sbtr[N];
int H;
int mn[N];
int find(int x){
	if(par[x]==x)return x;
	return par[x]=find(par[x]);
}
void unite(int x, int y){
	int px=find(x),py=find(y);
	if(px==py)return;
	if(sbtr[py]>sbtr[px])swap(px,py);
	
	if(sbtr[py]%2 and sbtr[px]%2){
		H-=mn[py];
		H-=mn[px];
	}
	else if(sbtr[py]%2){
		H+=mn[py];
		H-=max(mn[py],mn[px]);
	}
	else if(sbtr[px]%2){
		H+=mn[px];
		H-=max(mn[py],mn[px]);
	}
	
	sbtr[px]+=sbtr[py];
	par[py]=px;
	mn[py]=max(mn[py],mn[px]);
	
}
std::vector<long long> calculate_costs(std::vector<int> W, std::vector<int> A,
                                       std::vector<int> B, std::vector<int> E) {
    H=0;                                   	
	for(auto p:A)H+=p;                   	
    int q = (int)E.size();
    int n = W.size();
    for(int i=0;i<n;i++){
		par[i]=i;
		sbtr[i]=1;
		mn[i]=A[i]-B[i];
	}
	
    vector<ll>ans(q);
    vector<pair<ll,ll> >v;
    vector<pair<ll, pair<int,int> > >vc;
    for(int i=0;i<n;i++){
    	v.pb({W[i],i});
	}
	sort(v.begin(),v.end());
	for(int i=1;i<n;i++){
		int x=abs(v[i].ff-v[i-1].ff);
		int a=v[i-1].ss,b=v[i].ss;
		vc.pb({x,{a,b}});
	}
	sort(vc.begin(),vc.end());
	int idx=0;
	vector<pair<int,int>>vec;
	for(int i=0;i<q;i++){
		vec.pb({E[i],i});
	}
	sort(vec.begin(),vec.end());
	
	for(int f=0;f<q;f++){
		ll d=vec[f].ff;
		int k=vec[f].ss;
		while(vc[idx].ff<=d and idx<vc.size()){
			int a=vc[idx].ss.ff,b=vc[idx].ss.ss;
			unite(a,b);
			idx++;
		}
		ans[k]=H;
	}
	return ans;
}

Compilation message

nile.cpp: In function 'std::vector<long long int> calculate_costs(std::vector<int>, std::vector<int>, std::vector<int>, std::vector<int>)':
nile.cpp:74:30: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<long long int, std::pair<int, int> > >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   74 |   while(vc[idx].ff<=d and idx<vc.size()){
      |                           ~~~^~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 2384 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 2 ms 2640 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 30 ms 11456 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 39 ms 11456 KB Output is correct
2 Correct 37 ms 11432 KB Output is correct
3 Correct 39 ms 11456 KB Output is correct
4 Correct 40 ms 11448 KB Output is correct
5 Correct 43 ms 11456 KB Output is correct
6 Correct 42 ms 11448 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Incorrect 2 ms 2640 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 2 ms 2640 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 39 ms 11456 KB Output is correct
2 Correct 37 ms 11432 KB Output is correct
3 Correct 39 ms 11456 KB Output is correct
4 Correct 40 ms 11448 KB Output is correct
5 Correct 43 ms 11456 KB Output is correct
6 Correct 42 ms 11448 KB Output is correct
7 Correct 61 ms 12984 KB Output is correct
8 Correct 67 ms 12984 KB Output is correct
9 Correct 67 ms 13000 KB Output is correct
10 Correct 72 ms 13004 KB Output is correct
11 Correct 65 ms 12992 KB Output is correct
12 Correct 69 ms 12992 KB Output is correct
13 Correct 65 ms 12992 KB Output is correct
14 Correct 61 ms 12992 KB Output is correct
15 Correct 64 ms 12996 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 2384 KB Output isn't correct
2 Halted 0 ms 0 KB -