# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
498465 | Yuisuyuno | Palembang Bridges (APIO15_bridge) | C++14 | 42 ms | 7288 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.
//Nguyen Huu Hoang Minh
#include <bits/stdc++.h>
#define sz(x) int(x.size())
#define all(x) x.begin(),x.end()
#define reset(x) memset(x, 0,sizeof(x))
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define N 100005
#define remain(x) if (x > MOD) x -= MOD
#define ii pair<int, int>
#define iiii pair< ii , ii >
#define viiii vector< iiii >
#define vi vector<int>
#define vii vector< ii >
#define bit(x, i) (((x) >> (i)) & 1)
#define Task "test"
#define int long long
using namespace std;
typedef long double ld;
const int inf = 1e10;
const int minf = -1e10;
int n, k;
struct ppl{
int s, t;
bool operator < (const ppl &a) const{
return s+t < a.s + a.t;
}
};
vector<ppl> Q;
int ans = 0;
void readfile()
{
ios_base::sync_with_stdio(false);
cin.tie(0);cout.tie(0);
if (fopen(Task".inp","r"))
{
freopen(Task".inp","r",stdin);
//freopen(Task".out","w",stdout);
}
cin >> k >> n;
for(int i=1; i<=n; i++){
char a, b;
int x, y;
cin >> a >> x >> b >> y;
if (a==b) ans += abs(x-y);
else{
Q.pb({x,y});
}
}
}
void solve1(){
vector<int> val;
for(int i=0; i<Q.size(); i++) val.pb(Q[i].s), val.pb(Q[i].t);
sort(all(val));
//val.erase(unique(all(val)),val.end());
int x = val[(val.size()+1)/2 - 1];
for(int i=0; i<Q.size(); i++){
ans += abs(Q[i].s - x) + abs(Q[i].t - x) + 1;
}
//cout << x << '\n';
cout << ans;
}
void proc()
{
if (k==1){
solve1();
return;
}
}
signed main()
{
readfile();
proc();
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... |