답안 #639699

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
639699 2022-09-11T07:00:53 Z LittleCube Reconstruction Project (JOI22_reconstruction) C++14
7 / 100
5000 ms 253748 KB
#include <bits/stdc++.h>
#define ll long long
#define pii pair<int, int>
#define pll pair<ll, ll>
#define F first
#define S second
using namespace std;

int N, M, Q, dsu[505];
pii E[100005];
ll w[100005], q[1000006], ans[1000006];
vector<int> mst[1000006];


int find(int k)
{
	return k == dsu[k] ? k : dsu[k] = find(dsu[k]);
}

void MST(int qdx, vector<int> &edx)
{
	if(!mst[qdx].empty())
		return;
	for(int i = 1; i <= N; i++)
		dsu[i] = i;
	sort(edx.begin(), edx.end(), [&](int i, int j){ return make_pair(abs(q[qdx] - w[i]), i) < make_pair(abs(q[qdx] - w[j]), j); });
	int cnt = N - 1;
	for(auto i : edx)
	{
		if(find(E[i].F) != find(E[i].S))
		{
			dsu[find(E[i].F)] = find(E[i].S);
			mst[qdx].emplace_back(i);
			cnt--;
		}
		if(!cnt) break;
	}
	sort(mst[qdx].begin(), mst[qdx].end());
}



signed main()
{
	ios::sync_with_stdio(0);
	cin.tie(0), cout.tie(0);
	cin >> N >> M;
	for(int i = 1; i <= M; i++)
		cin >> E[i].F >> E[i].S >> w[i];

	cin >> Q;
	vector<int> v;
	for(int i = 1; i <= M; i++)
		v.emplace_back(i);

	for(int i = 1; i <= Q; i++)
	{
		cin >> q[i];
		MST(i, v);
		for(int j : mst[i])
			ans[i] += abs(q[i] - w[j]);
		cout << ans[i] << '\n';
	}
	
}
# 결과 실행 시간 메모리 Grader output
1 Correct 12 ms 23764 KB Output is correct
2 Correct 11 ms 23812 KB Output is correct
3 Correct 12 ms 23760 KB Output is correct
4 Correct 12 ms 23764 KB Output is correct
5 Correct 12 ms 23812 KB Output is correct
6 Correct 12 ms 23816 KB Output is correct
7 Correct 13 ms 23772 KB Output is correct
8 Correct 14 ms 23816 KB Output is correct
9 Correct 12 ms 23780 KB Output is correct
10 Correct 13 ms 23764 KB Output is correct
11 Correct 12 ms 23764 KB Output is correct
12 Correct 13 ms 23732 KB Output is correct
13 Correct 13 ms 23764 KB Output is correct
14 Correct 13 ms 23800 KB Output is correct
15 Correct 13 ms 23812 KB Output is correct
16 Correct 14 ms 23708 KB Output is correct
17 Correct 13 ms 23936 KB Output is correct
18 Correct 12 ms 23808 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 12 ms 23764 KB Output is correct
2 Correct 11 ms 23812 KB Output is correct
3 Correct 12 ms 23760 KB Output is correct
4 Correct 12 ms 23764 KB Output is correct
5 Correct 12 ms 23812 KB Output is correct
6 Correct 12 ms 23816 KB Output is correct
7 Correct 13 ms 23772 KB Output is correct
8 Correct 14 ms 23816 KB Output is correct
9 Correct 12 ms 23780 KB Output is correct
10 Correct 13 ms 23764 KB Output is correct
11 Correct 12 ms 23764 KB Output is correct
12 Correct 13 ms 23732 KB Output is correct
13 Correct 13 ms 23764 KB Output is correct
14 Correct 13 ms 23800 KB Output is correct
15 Correct 13 ms 23812 KB Output is correct
16 Correct 14 ms 23708 KB Output is correct
17 Correct 13 ms 23936 KB Output is correct
18 Correct 12 ms 23808 KB Output is correct
19 Correct 13 ms 23764 KB Output is correct
20 Correct 105 ms 27688 KB Output is correct
21 Correct 125 ms 27624 KB Output is correct
22 Correct 115 ms 27728 KB Output is correct
23 Correct 107 ms 27724 KB Output is correct
24 Correct 108 ms 27648 KB Output is correct
25 Correct 102 ms 27744 KB Output is correct
26 Correct 112 ms 27652 KB Output is correct
27 Correct 111 ms 27720 KB Output is correct
28 Correct 96 ms 27612 KB Output is correct
29 Correct 92 ms 27712 KB Output is correct
30 Correct 99 ms 27636 KB Output is correct
31 Correct 110 ms 27728 KB Output is correct
32 Correct 114 ms 27628 KB Output is correct
33 Correct 103 ms 27712 KB Output is correct
34 Correct 71 ms 27784 KB Output is correct
35 Correct 88 ms 27728 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 13 ms 23720 KB Output is correct
2 Correct 12 ms 23764 KB Output is correct
3 Correct 11 ms 23764 KB Output is correct
4 Execution timed out 5068 ms 29956 KB Time limit exceeded
5 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 12 ms 23764 KB Output is correct
2 Correct 11 ms 23812 KB Output is correct
3 Correct 12 ms 23760 KB Output is correct
4 Correct 12 ms 23764 KB Output is correct
5 Correct 12 ms 23812 KB Output is correct
6 Correct 12 ms 23816 KB Output is correct
7 Correct 13 ms 23772 KB Output is correct
8 Correct 14 ms 23816 KB Output is correct
9 Correct 12 ms 23780 KB Output is correct
10 Correct 13 ms 23764 KB Output is correct
11 Correct 12 ms 23764 KB Output is correct
12 Correct 13 ms 23732 KB Output is correct
13 Correct 13 ms 23764 KB Output is correct
14 Correct 13 ms 23800 KB Output is correct
15 Correct 13 ms 23812 KB Output is correct
16 Correct 14 ms 23708 KB Output is correct
17 Correct 13 ms 23936 KB Output is correct
18 Correct 12 ms 23808 KB Output is correct
19 Correct 12 ms 23764 KB Output is correct
20 Execution timed out 5080 ms 253748 KB Time limit exceeded
21 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 12 ms 23764 KB Output is correct
2 Correct 11 ms 23812 KB Output is correct
3 Correct 12 ms 23760 KB Output is correct
4 Correct 12 ms 23764 KB Output is correct
5 Correct 12 ms 23812 KB Output is correct
6 Correct 12 ms 23816 KB Output is correct
7 Correct 13 ms 23772 KB Output is correct
8 Correct 14 ms 23816 KB Output is correct
9 Correct 12 ms 23780 KB Output is correct
10 Correct 13 ms 23764 KB Output is correct
11 Correct 12 ms 23764 KB Output is correct
12 Correct 13 ms 23732 KB Output is correct
13 Correct 13 ms 23764 KB Output is correct
14 Correct 13 ms 23800 KB Output is correct
15 Correct 13 ms 23812 KB Output is correct
16 Correct 14 ms 23708 KB Output is correct
17 Correct 13 ms 23936 KB Output is correct
18 Correct 12 ms 23808 KB Output is correct
19 Correct 13 ms 23764 KB Output is correct
20 Correct 105 ms 27688 KB Output is correct
21 Correct 125 ms 27624 KB Output is correct
22 Correct 115 ms 27728 KB Output is correct
23 Correct 107 ms 27724 KB Output is correct
24 Correct 108 ms 27648 KB Output is correct
25 Correct 102 ms 27744 KB Output is correct
26 Correct 112 ms 27652 KB Output is correct
27 Correct 111 ms 27720 KB Output is correct
28 Correct 96 ms 27612 KB Output is correct
29 Correct 92 ms 27712 KB Output is correct
30 Correct 99 ms 27636 KB Output is correct
31 Correct 110 ms 27728 KB Output is correct
32 Correct 114 ms 27628 KB Output is correct
33 Correct 103 ms 27712 KB Output is correct
34 Correct 71 ms 27784 KB Output is correct
35 Correct 88 ms 27728 KB Output is correct
36 Execution timed out 5068 ms 30420 KB Time limit exceeded
37 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 12 ms 23764 KB Output is correct
2 Correct 11 ms 23812 KB Output is correct
3 Correct 12 ms 23760 KB Output is correct
4 Correct 12 ms 23764 KB Output is correct
5 Correct 12 ms 23812 KB Output is correct
6 Correct 12 ms 23816 KB Output is correct
7 Correct 13 ms 23772 KB Output is correct
8 Correct 14 ms 23816 KB Output is correct
9 Correct 12 ms 23780 KB Output is correct
10 Correct 13 ms 23764 KB Output is correct
11 Correct 12 ms 23764 KB Output is correct
12 Correct 13 ms 23732 KB Output is correct
13 Correct 13 ms 23764 KB Output is correct
14 Correct 13 ms 23800 KB Output is correct
15 Correct 13 ms 23812 KB Output is correct
16 Correct 14 ms 23708 KB Output is correct
17 Correct 13 ms 23936 KB Output is correct
18 Correct 12 ms 23808 KB Output is correct
19 Correct 13 ms 23764 KB Output is correct
20 Correct 105 ms 27688 KB Output is correct
21 Correct 125 ms 27624 KB Output is correct
22 Correct 115 ms 27728 KB Output is correct
23 Correct 107 ms 27724 KB Output is correct
24 Correct 108 ms 27648 KB Output is correct
25 Correct 102 ms 27744 KB Output is correct
26 Correct 112 ms 27652 KB Output is correct
27 Correct 111 ms 27720 KB Output is correct
28 Correct 96 ms 27612 KB Output is correct
29 Correct 92 ms 27712 KB Output is correct
30 Correct 99 ms 27636 KB Output is correct
31 Correct 110 ms 27728 KB Output is correct
32 Correct 114 ms 27628 KB Output is correct
33 Correct 103 ms 27712 KB Output is correct
34 Correct 71 ms 27784 KB Output is correct
35 Correct 88 ms 27728 KB Output is correct
36 Correct 13 ms 23720 KB Output is correct
37 Correct 12 ms 23764 KB Output is correct
38 Correct 11 ms 23764 KB Output is correct
39 Execution timed out 5068 ms 29956 KB Time limit exceeded
40 Halted 0 ms 0 KB -