# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
544888 | mgl_diamond | Palembang Bridges (APIO15_bridge) | C++14 | 106 ms | 4740 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;
#define ll long long
#define ii pair<int, int>
#define fi first
#define se second
#define debug(x) cout << #x << ": " << x << "\n"
#define all(x) x.begin(), x.end()
template<class T> bool umax(T &a, T b) { if (a<b) { a=b; return 1; } return 0; }
template<class T> bool umin(T &a, T b) { if (a>b) { a=b; return 1; } return 0; }
void setIO(string name) {
ios_base::sync_with_stdio(0); cin.tie(0);
freopen((name+".inp").c_str(),"r",stdin);
freopen((name+".out").c_str(),"w",stdout);
}
const int mxN=100100;
int k, n;
char p[mxN], q[mxN];
int x[mxN], y[mxN];
ll ans;
vector<int> v;
void solve1() {
for(int i=1; i<=n; ++i)
if (p[i]==q[i]) ans+=abs(x[i]-y[i]);
else v.push_back(x[i]),
v.push_back(y[i]);
sort(all(v));
int t=v.size();
for(int i=0; i<t; ++i)
ans+=abs(v[t/2]-v[i]);
cout << ans+v.size()/2 << '\n';
}
int main() {
cin >> k >> n;
for(int i=1; i<=n; ++i)
cin >> p[i] >> x[i] >> q[i] >> y[i];
if (k==1) solve1();
//else solve2();
}
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... |