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 rep(i,a,n) for (int i=a;i<n;i++)
#define per(i,a,n) for (int i=n-1;i>=a;i--)
#define pb push_back
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second
#define SZ(x) ((int)(x).size())
typedef long long ll;
typedef long double ld;
typedef pair<int, int> ii;
const int mod = (int) 1e9 + 7;
const ll inf = 1LL << 60;
const int maxn = (int) 1e5 + 5;
const ld eps = 1e-9;
int n, k;
vector<ii> a;
vector<int> v;
ll add, res;
int main() {
//freopen("test.txt", "r", stdin);
ios_base::sync_with_stdio(0); cin.tie(0);
cin >> k >> n;
rep(i, 1, n + 1) {
char x, y;
int l, r;
cin >> x >> l >> y >> r;
if(l > r) swap(l, r);
if(x == y) add += r - l;
else {
a.pb(ii(l, r));
v.pb(l);
v.pb(r);
}
}
sort(all(v));
int p = v[SZ(v) / 2];
//cout << p << endl;
for (auto i : a) res += 1 + abs(i.fi - p) + abs(i.se - p);
res += add;
cout << res << endl;
}
# | 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... |