This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#pragma GCC optimize("O3,unroll-loops")
#include <bits/stdc++.h>
#pragma pack(0)
#define ll long long
#define pii pair<ll, ll>
#define pll pair<ll, ll>
#define F first
#define S second
#define MOD 1000000007
#define MOD2 998244353
#define _INFINITY 9223372036854775807
#define fast ios::sync_with_stdio(0), cin.tie(0)
using namespace std;
ll n, k, ans;
vector<int> v;
signed main()
{
fast;
cin >> k >> n;
for (int i = 1; i <= n; i++)
{
char c1, c2;
int p1, p2;
cin >> c1 >> p1 >> c2 >> p2;
if (c1 == c2)
ans += 2 * abs(p1 - p2);
else
{
v.emplace_back(p1);
v.emplace_back(p2);
}
}
sort(v.begin(), v.end());
if (v.size() % 2)
{
int mid = 2 * v[v.size() / 2];
for (int i : v)
ans += abs(mid - i * 2) + 1;
}
else if(v.size() > 0)
{
int mid = v[v.size() / 2] + v[v.size() / 2 - 1];
for (int i : v)
ans += abs(mid - i * 2) + 1;
}
cout << ans / 2 << '\n';
}
# | 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... |