Submission #370120

# Submission time Handle Problem Language Result Execution time Memory
370120 2021-02-23T10:39:31 Z Bill_00 Palembang Bridges (APIO15_bridge) C++14
0 / 100
1 ms 492 KB
#include <bits/stdc++.h>
#define ff first
#define ss second
#define mp make_pair
#define pb push_back
#define pp push
#define MOD 1000000007
#define INF 1e18
#define N 100005
#define M 5000000
typedef long long ll;
using namespace std;
ll x[N],y[N],l[N],r[N],ans;
pair<ll,bool>p[2*N];
int main(){
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
 	ll o,n;
 	cin >> o >> n;
 	for(ll i=1;i<=n;i++){
 		char a,b;
 		cin >> a >> x[i] >> b >> y[i];
 		if(x[i]>y[i]) swap(x[i],y[i]);
 		ans+=(y[i]-x[i]);
 		if(a!=b){
 			ans++;
 			p[i*2-1].ff=x[i];
 			p[i*2-1].ss=0;
 			p[i*2].ff=y[i];
 			p[i*2].ss=1;
 		}
 	}
 	sort(p+1,p+2*n+1);
 	ll k=0,last=0,val=0;
 	for(ll i=1;i<=2*n;i++){
 		val+=((p[i].ff-last)*k);
 		l[i]=val*2;
 		if(p[i].ss==1){
 			k++;
 			last=p[i].ff;
 		}
 	}
 	k=0,last=10000000000,val=0;
 	for(ll i=2*n;i>=1;i--){
 		val+=((last-p[i].ff)*k);
 		r[i]=val*2;
 		if(p[i].ss==0){
 			k++;
 			last=p[i].ff;
 		}
 	}
 	ll x=LLONG_MAX;
 	for(ll i=1;i<=2*n;i++){
 		x=min(x,l[i]+r[i]);
 	}
 	cout << x+ans;

 
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 492 KB Output is correct
4 Incorrect 1 ms 492 KB Output isn't correct
5 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 492 KB Output is correct
4 Incorrect 1 ms 492 KB Output isn't correct
5 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Incorrect 1 ms 364 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Incorrect 1 ms 364 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Incorrect 1 ms 364 KB Output isn't correct
4 Halted 0 ms 0 KB -