| # | Time | Username | Problem | Language | Result | Execution time | Memory |
|---|---|---|---|---|---|---|---|
| 640688 | makanhulia | Palembang Bridges (APIO15_bridge) | C++17 | 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;
#pragma GCC optimize("Ofast")
typedef long long ll;
// const ll mod = 1e9 + 7;
const ll MAXN = 1e6 + 5;
#define vi vector<int>
#define vll vector<ll>
#define pii pair<int, int>
#define pll pair<ll, ll>
#define mp make_pair
#define pb push_back
#define lb lower_bound
#define ub upper_bound
#define fi first
#define sc second
#define endl '\n'
#define gl ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
int main()
{
gl;
ll k, n;
cin >> k >> n;
ll sum = 0;
vll v;
for (int i = 0; i < n; i++)
{
char a, b;
ll x, y;
cin >> a >> x >> b >> y;
if (a == b)
sum += abs(x - y);
else
{
sum++;
v.pb(x);
v.pb(y);
}
}
sort(v.begin(), v.end());
vll ps(v.size(), 0);
ll ans = 1e18;
for (int i = 0; i < v.size(); i++)
{
ps[i] = v[i];
if (i > 0)
ps[i] += ps[i - 1];
}
ll l = v[0], r = v[v.size() - 1];
while (l <= r)
{
ll m = (l + r) / 2;
ll pos = ub(v.begin(), v.end(), m) - v.begin();
if (pos > 0)
pos--;
ans = min(ans, (ll)(m * (pos + 1) - ps[pos] - m * (v.size() - pos - 1) + ps[v.size() - 1] - ps[pos]));
if (m * (pos + 1) - ps[pos] <= m * (v.size() - pos - 1) - ps[v.size() - 1] + ps[pos])
{
l = m + 1;
}
else
{
r = m - 1;
}
}
if (ans == 1e18)
ans = 0;
cout << ans + sum << endl;
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... | ||||
