Submission #602986

# Submission time Handle Problem Language Result Execution time Memory
602986 2022-07-23T13:43:43 Z Fidan Palembang Bridges (APIO15_bridge) C++17
22 / 100
108 ms 3956 KB
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll inf=(1e18)+10;
int main(){
	ll k, n;
	cin>>k>>n;
	if(k==1){
		ll sum=0, i;
		vector<pair<ll, ll>> v;
		vector<ll> v1;
		
		for(i=0; i<n; i++){
			char c1, c2;
			ll i1, i2;
			cin>>c1>>i1>>c2>>i2;
			sum+=abs(i1-i2);
			if(c1!=c2){
				sum++;
				v.push_back({i1, i2});
				v1.push_back(i1);
				v1.push_back(i2);
			}
		}
		
		sort(v1.begin(), v1.end());
		k=v1.size();
		if(k==0){
			cout<<sum;
			return 0;
		}
		ll cvb=v1[k/2];
		
		for(auto p: v){
			ll a1=p.first, a2=p.second;
			if(min(a1, a2)>cvb) sum+=2*(min(a1, a2)-cvb);
			else if(max(a1, a2)<cvb) sum+=2*(cvb-max(a1, a2));
		}
		cout<<sum;
	}
	return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 2 ms 312 KB Output is correct
6 Correct 1 ms 316 KB Output is correct
7 Correct 2 ms 340 KB Output is correct
8 Correct 2 ms 340 KB Output is correct
9 Correct 2 ms 340 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 1 ms 340 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 2 ms 340 KB Output is correct
8 Correct 1 ms 368 KB Output is correct
9 Correct 2 ms 340 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 1 ms 340 KB Output is correct
12 Correct 47 ms 3884 KB Output is correct
13 Correct 108 ms 3952 KB Output is correct
14 Correct 67 ms 3736 KB Output is correct
15 Correct 68 ms 2528 KB Output is correct
16 Correct 77 ms 3796 KB Output is correct
17 Correct 96 ms 3884 KB Output is correct
18 Correct 88 ms 3880 KB Output is correct
19 Correct 102 ms 3856 KB Output is correct
20 Correct 84 ms 3868 KB Output is correct
21 Correct 103 ms 3956 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 212 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 212 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 212 KB Output isn't correct
2 Halted 0 ms 0 KB -