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>
#define ll long long
#define pb push_back
#define mp make_pair
using namespace std;
const int maxn = 100100;
ll s[maxn], f[maxn], n, k;
char szone[maxn], fzone[maxn];
int main() {
cin>>k>>n;
ll result = 0LL;
vector<ll>v;
for(int i=1;i<=n;i++) {
cin>>szone[i]>>s[i];
cin>>fzone[i]>>f[i];
if(szone[i] == fzone[i]) result += abs(f[i] - s[i]);
v.pb(s[i]);
v.pb(f[i]);
}
if(k == 1) {
ll mintemp = LLONG_MAX;
for(int i:v) {
ll temp = 0LL;
for(int j=1;j<=n;j++) {
if(szone[j] != fzone[j]) {
temp += abs(s[j] - i) + abs(f[j] - i) + 1;
}
}
mintemp = min(mintemp, temp);
//cout<<i<<": "<<temp<<"\n";
}
result += mintemp;
cout<<result<<"\n";
return 0;
}
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... |