답안 #951580

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
951580 2024-03-22T07:03:51 Z pcc Reconstruction Project (JOI22_reconstruction) C++17
14 / 100
1709 ms 46396 KB
#include <bits/stdc++.h>
using namespace std;

#define ll long long
#define al3 array<ll,3>
#define pll pair<ll,ll>
#define fs first
#define sc second

const int mxn = 1e5+10;
int N,M,Q;
array<ll,3> edges[mxn];

struct DSU{
	int dsu[550],sz[550];
	void init(int n){
		for(int i = 0;i<=n;i++){
			dsu[i] = i;
			sz[i] = 1;
		}
	}
	int root(int k){
		return k == dsu[k]?k:dsu[k] = root(dsu[k]);
	}
	void onion(int a,int b){
		 a = root(a),b = root(b);
		 if(a == b)return;
		 if(sz[a]<sz[b])swap(a,b);
		 dsu[b] = a;
		 sz[a] += sz[b];
		 return;
	}
};

namespace S1{
	DSU dsu;
	void solve(){
		ll K;
		cin>>K;
		sort(edges,edges+M,[&](al3 &a,al3 &b){return abs(a[0]-K)<abs(b[0]-K);});
		dsu.init(N);
		ll ans = 0;
		for(int i = 0;i<M;i++){
			auto [w,a,b] = edges[i];
			if(dsu.root(a) == dsu.root(b))continue;
			ans += abs(w-K);
			dsu.onion(a,b);
		}
		cout<<ans<<'\n';
		return;
	}
}

namespace S2{
	vector<pll> req;
	ll ans[mxn*10];
	vector<int> v[550];
	int ptr[550];
	void solve(){
		for(int i = 0;i<M;i++){
			v[min(edges[i][1],edges[i][2])].push_back(edges[i][0]);
		}
		for(int i = 1;i<=N;i++){
			sort(v[i].begin(),v[i].end());
		}
		for(int i = 1;i<=Q;i++){
			ll k;
			cin>>k;
			req.push_back(pll(k,i));
		}
		sort(req.begin(),req.end());
		for(auto &i:req){
			ll tans = 0;
			for(int j = 1;j<N;j++){
				while(ptr[j]+1<v[j].size()&&abs(v[j][ptr[j]]-i.fs)>=abs(v[j][ptr[j]+1]-i.fs))ptr[j]++;
				tans += abs(v[j][ptr[j]]-i.fs);
			}
			ans[i.sc] = tans;
		}
		for(int i = 1;i<=Q;i++){
			cout<<ans[i]<<'\n';
		}
		return;
	}
}

int main(){
	ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
	cin>>N>>M;
	for(int i = 0;i<M;i++){
		int a,b,c;
		cin>>a>>b>>c;
		edges[i] = array<ll,3>({c,a,b});
	}
	cin>>Q;
	if(Q<=10)while(Q--)S1::solve();
	else S2::solve();
}

Compilation message

reconstruction.cpp: In function 'void S2::solve()':
reconstruction.cpp:75:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   75 |     while(ptr[j]+1<v[j].size()&&abs(v[j][ptr[j]]-i.fs)>=abs(v[j][ptr[j]+1]-i.fs))ptr[j]++;
      |           ~~~~~~~~^~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 2392 KB Output is correct
2 Correct 1 ms 2396 KB Output is correct
3 Correct 0 ms 2396 KB Output is correct
4 Correct 1 ms 2396 KB Output is correct
5 Correct 2 ms 2396 KB Output is correct
6 Correct 0 ms 2396 KB Output is correct
7 Correct 1 ms 2396 KB Output is correct
8 Correct 0 ms 2396 KB Output is correct
9 Correct 0 ms 2396 KB Output is correct
10 Correct 1 ms 2396 KB Output is correct
11 Correct 0 ms 2396 KB Output is correct
12 Correct 0 ms 2396 KB Output is correct
13 Correct 1 ms 2396 KB Output is correct
14 Correct 1 ms 2396 KB Output is correct
15 Correct 0 ms 2396 KB Output is correct
16 Correct 2 ms 2396 KB Output is correct
17 Correct 1 ms 2396 KB Output is correct
18 Correct 1 ms 2392 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 2392 KB Output is correct
2 Correct 1 ms 2396 KB Output is correct
3 Correct 0 ms 2396 KB Output is correct
4 Correct 1 ms 2396 KB Output is correct
5 Correct 2 ms 2396 KB Output is correct
6 Correct 0 ms 2396 KB Output is correct
7 Correct 1 ms 2396 KB Output is correct
8 Correct 0 ms 2396 KB Output is correct
9 Correct 0 ms 2396 KB Output is correct
10 Correct 1 ms 2396 KB Output is correct
11 Correct 0 ms 2396 KB Output is correct
12 Correct 0 ms 2396 KB Output is correct
13 Correct 1 ms 2396 KB Output is correct
14 Correct 1 ms 2396 KB Output is correct
15 Correct 0 ms 2396 KB Output is correct
16 Correct 2 ms 2396 KB Output is correct
17 Correct 1 ms 2396 KB Output is correct
18 Correct 1 ms 2392 KB Output is correct
19 Correct 0 ms 2396 KB Output is correct
20 Correct 64 ms 4192 KB Output is correct
21 Correct 65 ms 4184 KB Output is correct
22 Correct 78 ms 4248 KB Output is correct
23 Correct 66 ms 4188 KB Output is correct
24 Correct 64 ms 4320 KB Output is correct
25 Correct 64 ms 4184 KB Output is correct
26 Correct 73 ms 4184 KB Output is correct
27 Correct 71 ms 4188 KB Output is correct
28 Correct 48 ms 4324 KB Output is correct
29 Correct 44 ms 4188 KB Output is correct
30 Correct 62 ms 4320 KB Output is correct
31 Correct 71 ms 4184 KB Output is correct
32 Correct 68 ms 4184 KB Output is correct
33 Correct 67 ms 4328 KB Output is correct
34 Correct 44 ms 4188 KB Output is correct
35 Correct 50 ms 4192 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 2392 KB Output is correct
2 Correct 1 ms 2396 KB Output is correct
3 Correct 1 ms 2396 KB Output is correct
4 Correct 1707 ms 42452 KB Output is correct
5 Correct 1698 ms 44260 KB Output is correct
6 Correct 1674 ms 44624 KB Output is correct
7 Correct 1185 ms 45968 KB Output is correct
8 Correct 1067 ms 45988 KB Output is correct
9 Correct 959 ms 46396 KB Output is correct
10 Correct 1709 ms 44156 KB Output is correct
11 Correct 1103 ms 46220 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 2392 KB Output is correct
2 Correct 1 ms 2396 KB Output is correct
3 Correct 0 ms 2396 KB Output is correct
4 Correct 1 ms 2396 KB Output is correct
5 Correct 2 ms 2396 KB Output is correct
6 Correct 0 ms 2396 KB Output is correct
7 Correct 1 ms 2396 KB Output is correct
8 Correct 0 ms 2396 KB Output is correct
9 Correct 0 ms 2396 KB Output is correct
10 Correct 1 ms 2396 KB Output is correct
11 Correct 0 ms 2396 KB Output is correct
12 Correct 0 ms 2396 KB Output is correct
13 Correct 1 ms 2396 KB Output is correct
14 Correct 1 ms 2396 KB Output is correct
15 Correct 0 ms 2396 KB Output is correct
16 Correct 2 ms 2396 KB Output is correct
17 Correct 1 ms 2396 KB Output is correct
18 Correct 1 ms 2392 KB Output is correct
19 Correct 1 ms 2396 KB Output is correct
20 Runtime error 117 ms 36604 KB Execution killed with signal 11
21 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 2392 KB Output is correct
2 Correct 1 ms 2396 KB Output is correct
3 Correct 0 ms 2396 KB Output is correct
4 Correct 1 ms 2396 KB Output is correct
5 Correct 2 ms 2396 KB Output is correct
6 Correct 0 ms 2396 KB Output is correct
7 Correct 1 ms 2396 KB Output is correct
8 Correct 0 ms 2396 KB Output is correct
9 Correct 0 ms 2396 KB Output is correct
10 Correct 1 ms 2396 KB Output is correct
11 Correct 0 ms 2396 KB Output is correct
12 Correct 0 ms 2396 KB Output is correct
13 Correct 1 ms 2396 KB Output is correct
14 Correct 1 ms 2396 KB Output is correct
15 Correct 0 ms 2396 KB Output is correct
16 Correct 2 ms 2396 KB Output is correct
17 Correct 1 ms 2396 KB Output is correct
18 Correct 1 ms 2392 KB Output is correct
19 Correct 0 ms 2396 KB Output is correct
20 Correct 64 ms 4192 KB Output is correct
21 Correct 65 ms 4184 KB Output is correct
22 Correct 78 ms 4248 KB Output is correct
23 Correct 66 ms 4188 KB Output is correct
24 Correct 64 ms 4320 KB Output is correct
25 Correct 64 ms 4184 KB Output is correct
26 Correct 73 ms 4184 KB Output is correct
27 Correct 71 ms 4188 KB Output is correct
28 Correct 48 ms 4324 KB Output is correct
29 Correct 44 ms 4188 KB Output is correct
30 Correct 62 ms 4320 KB Output is correct
31 Correct 71 ms 4184 KB Output is correct
32 Correct 68 ms 4184 KB Output is correct
33 Correct 67 ms 4328 KB Output is correct
34 Correct 44 ms 4188 KB Output is correct
35 Correct 50 ms 4192 KB Output is correct
36 Incorrect 61 ms 7888 KB Output isn't correct
37 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 2392 KB Output is correct
2 Correct 1 ms 2396 KB Output is correct
3 Correct 0 ms 2396 KB Output is correct
4 Correct 1 ms 2396 KB Output is correct
5 Correct 2 ms 2396 KB Output is correct
6 Correct 0 ms 2396 KB Output is correct
7 Correct 1 ms 2396 KB Output is correct
8 Correct 0 ms 2396 KB Output is correct
9 Correct 0 ms 2396 KB Output is correct
10 Correct 1 ms 2396 KB Output is correct
11 Correct 0 ms 2396 KB Output is correct
12 Correct 0 ms 2396 KB Output is correct
13 Correct 1 ms 2396 KB Output is correct
14 Correct 1 ms 2396 KB Output is correct
15 Correct 0 ms 2396 KB Output is correct
16 Correct 2 ms 2396 KB Output is correct
17 Correct 1 ms 2396 KB Output is correct
18 Correct 1 ms 2392 KB Output is correct
19 Correct 0 ms 2396 KB Output is correct
20 Correct 64 ms 4192 KB Output is correct
21 Correct 65 ms 4184 KB Output is correct
22 Correct 78 ms 4248 KB Output is correct
23 Correct 66 ms 4188 KB Output is correct
24 Correct 64 ms 4320 KB Output is correct
25 Correct 64 ms 4184 KB Output is correct
26 Correct 73 ms 4184 KB Output is correct
27 Correct 71 ms 4188 KB Output is correct
28 Correct 48 ms 4324 KB Output is correct
29 Correct 44 ms 4188 KB Output is correct
30 Correct 62 ms 4320 KB Output is correct
31 Correct 71 ms 4184 KB Output is correct
32 Correct 68 ms 4184 KB Output is correct
33 Correct 67 ms 4328 KB Output is correct
34 Correct 44 ms 4188 KB Output is correct
35 Correct 50 ms 4192 KB Output is correct
36 Correct 1 ms 2392 KB Output is correct
37 Correct 1 ms 2396 KB Output is correct
38 Correct 1 ms 2396 KB Output is correct
39 Correct 1707 ms 42452 KB Output is correct
40 Correct 1698 ms 44260 KB Output is correct
41 Correct 1674 ms 44624 KB Output is correct
42 Correct 1185 ms 45968 KB Output is correct
43 Correct 1067 ms 45988 KB Output is correct
44 Correct 959 ms 46396 KB Output is correct
45 Correct 1709 ms 44156 KB Output is correct
46 Correct 1103 ms 46220 KB Output is correct
47 Correct 1 ms 2396 KB Output is correct
48 Runtime error 117 ms 36604 KB Execution killed with signal 11
49 Halted 0 ms 0 KB -