# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
585451 | messiuuuuu | Palembang Bridges (APIO15_bridge) | C++17 | 43 ms | 4300 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>
#define task "A"
#define ll long long
#define ld long double
#define fi first
#define se second
#define pb push_back
using namespace std;
const int MAXN = 1e5 + 5;
const ll INF = 1e18 + 5;
int n, k;
struct TRoad
{
char h, o;
ll ph, po;
}a[MAXN];
void Input()
{
cin >> k >> n;
for (int i = 1; i <= n; i++)
{
cin >> a[i].h >> a[i].ph >> a[i].o >> a[i].po;
}
}
ll Cal(int p)
{
ll res = 0;
for (int i = 1; i <= n; i++)
{
if (a[i].h == a[i].o)
{
res += abs(a[i].ph - a[i].po);
} else
{
res += abs(a[i].ph - p) + abs(a[i].po - p) + 1;
}
}
return res;
}
void Solve()
{
int l = 0, r = 1e9;
while (l <= r)
{
int mid = (l + r) / 2;
if (mid == n)
break;
if (Cal(mid) >= Cal(mid + 1))
l = mid + 1;
else
r = mid - 1;
}
cout << Cal(l);
}
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
if (fopen(task".INP","r"))
{
freopen(task".INP","r",stdin);
//freopen(task".OUT","w",stdout);
}
Input();
Solve();
}
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... |