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
#define sz(x) (int)x.size()
#define ff first
#define ss second
const int N = 300005;
const int M = 1e9 + 7;
int T, n, k, s1[N], s2[N];
char c1[N], c2[N];
signed main(){
ios::sync_with_stdio(false); cin.tie(0);
cin >> k >> n;
for(int i = 1; i <= n; i++){
cin >> c1[i] >> s1[i] >> c2[i] >> s2[i];
}
if(k == 1){
int ans = 0;
vector <int> v;
for(int i = 1; i <= n; i++){
if(c1[i] == c2[i]){
ans += abs(s1[i]-s2[i]);
}
else {
v.push_back(s1[i]);
v.push_back(s2[i]);
}
}
sort(v.begin(), v.end());
int x = 0;
if(sz(v) > 0) x = (v.front()+v.back()+1) / 2;
for(auto i : v){
ans += abs(i-x);
}
cout << ans+sz(v)/2 << "\n";
return 0;
}
}
# | 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... |