# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
575395 | AJ00 | Toll (APIO13_toll) | C++14 | 1 ms | 340 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
using namespace std;
#define int long long
int n;
const int MOD = 1000000007;
const int INF = 1e18;
int s[100001],t[100001];
vector<int> v,cons;
signed main()
{
//freopen("problemname.in", "r", stdin);
//freopen("problemname.out", "w", stdout);
ios_base::sync_with_stdio(false);
cin.tie(0);
int tc=1,q,k,m,c;
//cin >> tc;
for (int poppo = 1; poppo <= tc; poppo++){
//cout << "Case #" << poppo << ": ";
int n,k;
int ans = 0;
char ch1,ch2;
cin >> k >> n;
for (int i = 0; i < n; i++){
cin >> ch1 >> s[i] >> ch2 >> t[i];
if (ch1 == ch2){
ans += abs(s[i]-t[i]);
}
else {
v.push_back(s[i]);
v.push_back(t[i]);
cons.push_back(i);
}
}
ans += (int)cons.size();
if (v.size()){
sort(v.begin(),v.end());
// 0,1,2,3,.... 2n
int bridge = v[((v.size()-1)/2)];
for (int i = 0; i < cons.size(); i++){
ans += abs(s[cons[i]]-bridge) + abs(t[cons[i]]-bridge);
}
}
cout << ans << "\n";
}
return 0;
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |