Submission #1042418

# Submission time Handle Problem Language Result Execution time Memory
1042418 2024-08-03T04:15:14 Z Math4Life2020 Palembang Bridges (APIO15_bridge) C++17
63 / 100
2000 ms 10328 KB
#include <bits/stdc++.h>
using namespace std;
using ll = long long; using pii = pair<ll,ll>;

ll calc(vector<ll> v) {
	vector<ll> v2=v;
	sort(v2.begin(),v2.end());
	ll val = 0;
	for (ll x: v2) {
		val += abs(x-v2[v2.size()/2]);
	}
	return val;
}

int main() {
	ios_base::sync_with_stdio(false); cin.tie(0);
	ll K,N; cin >> K >> N;
	vector<pii> v;
	ll ans = 0;
	for (ll i=0;i<N;i++) {
		string p,q; ll s,t;
		cin >> p >> s >> q >> t;
		if (p==q) {
			ans += abs(s-t);
		} else {
			ans++;
			v.push_back({min(s,t),max(s,t)});
		}
	}
	vector<ll> v2;
	for (pii p0: v) {
		v2.push_back(p0.first);
		v2.push_back(p0.second);
	}
	sort(v2.begin(),v2.end());
	if (K==1) {
		cout << ans+calc(v2);
	} else {
		ll ans1[v.size()+1]; ll ans2[v.size()+1];
		vector<array<ll,3>> VTOT;
		for (ll i=0;i<v.size();i++) {
			VTOT.push_back({v[i].first+v[i].second,v[i].first,v[i].second});
		}
		sort(VTOT.begin(),VTOT.end());
		ans1[0]=0; ans2[v.size()]=0;
		vector<ll> vf; vector<ll> vb;
		for (ll T=0;T<VTOT.size();T++) {
			vf.push_back(VTOT[T][1]);
			vf.push_back(VTOT[T][2]);
			ans1[T+1]=calc(vf);
			vb.push_back(VTOT[v.size()-1-T][1]);
			vb.push_back(VTOT[v.size()-1-T][2]);
			ans2[v.size()-1-T]=calc(vb);
		}
		ll atotM = 1e18;
		for (ll i=0;i<=v.size();i++) {
			atotM = min(atotM,ans1[i]+ans2[i]);
		}
		cout << ans+atotM;
	}
}

Compilation message

bridge.cpp: In function 'int main()':
bridge.cpp:41:16: warning: comparison of integer expressions of different signedness: 'll' {aka 'long long int'} and 'std::vector<std::pair<long long int, long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   41 |   for (ll i=0;i<v.size();i++) {
      |               ~^~~~~~~~~
bridge.cpp:47:16: warning: comparison of integer expressions of different signedness: 'll' {aka 'long long int'} and 'std::vector<std::array<long long int, 3> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   47 |   for (ll T=0;T<VTOT.size();T++) {
      |               ~^~~~~~~~~~~~
bridge.cpp:56:16: warning: comparison of integer expressions of different signedness: 'll' {aka 'long long int'} and 'std::vector<std::pair<long long int, long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   56 |   for (ll i=0;i<=v.size();i++) {
      |               ~^~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 1 ms 492 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
7 Correct 1 ms 344 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 1 ms 344 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 1 ms 464 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 1 ms 348 KB Output is correct
12 Correct 21 ms 7536 KB Output is correct
13 Correct 34 ms 8944 KB Output is correct
14 Correct 27 ms 7252 KB Output is correct
15 Correct 23 ms 5456 KB Output is correct
16 Correct 23 ms 8268 KB Output is correct
17 Correct 26 ms 9040 KB Output is correct
18 Correct 36 ms 8784 KB Output is correct
19 Correct 37 ms 8952 KB Output is correct
20 Correct 25 ms 8532 KB Output is correct
21 Correct 35 ms 8776 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 1 ms 456 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 1 ms 480 KB Output is correct
5 Correct 0 ms 452 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 1 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 456 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 1 ms 348 KB Output is correct
9 Correct 0 ms 416 KB Output is correct
10 Correct 1 ms 348 KB Output is correct
11 Correct 0 ms 456 KB Output is correct
12 Correct 1 ms 344 KB Output is correct
13 Correct 15 ms 668 KB Output is correct
14 Correct 48 ms 656 KB Output is correct
15 Correct 65 ms 600 KB Output is correct
16 Correct 3 ms 348 KB Output is correct
17 Correct 14 ms 608 KB Output is correct
18 Correct 8 ms 348 KB Output is correct
19 Correct 14 ms 604 KB Output is correct
20 Correct 14 ms 600 KB Output is correct
21 Correct 32 ms 604 KB Output is correct
22 Correct 15 ms 604 KB Output is correct
23 Correct 13 ms 604 KB Output is correct
24 Correct 18 ms 684 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 1 ms 348 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 13 ms 664 KB Output is correct
14 Correct 47 ms 604 KB Output is correct
15 Correct 59 ms 600 KB Output is correct
16 Correct 2 ms 348 KB Output is correct
17 Correct 15 ms 616 KB Output is correct
18 Correct 8 ms 600 KB Output is correct
19 Correct 14 ms 600 KB Output is correct
20 Correct 14 ms 464 KB Output is correct
21 Correct 32 ms 632 KB Output is correct
22 Correct 21 ms 604 KB Output is correct
23 Correct 15 ms 784 KB Output is correct
24 Correct 14 ms 692 KB Output is correct
25 Execution timed out 2065 ms 10328 KB Time limit exceeded
26 Halted 0 ms 0 KB -