Submission #585459

#TimeUsernameProblemLanguageResultExecution timeMemory
585459mnngPalembang Bridges (APIO15_bridge)C++14
0 / 100
1 ms468 KiB
#include<bits/stdc++.h>
#define ll long long
#define pb push_back
using namespace std;
const int maxN = 1e5+1;
int k, n;
struct Tbridge
{
    char a, b;
    ll x, y;
    bool chk;
}p[maxN];
ll ans = 0;

void Input()
{
    vector<ll> v;
    cin >> k >> n;
    for(int i = 1; i <= n; i++)
    {
        cin >> p[i].a >> p[i].x >> p[i].b >> p[i].y;
        if(p[i].a == p[i].b)
        {
             ans += abs(p[i].y - p[i].x);
             p[i].chk = false;
        }
        else
        {
            v.pb(p[i].x);
            v.pb(p[i].y);
            p[i].chk = true;
        }
    }
    sort(v.begin(), v.end());
    if(k == 1)
    {
        ll res = (int)v.size() / 2;
        ll h = v[res];
        for(int i = 1; i <= n; i++)
            if(p[i].chk)
                ans += abs(h - p[i].x) + abs(h - p[i].y) + 1;
        cout << ans;
        return;
    }
   /* int res = v.size()/3;
    int h = v[res], h2 = v[res*2];
    for(int i = 1; i <= n; i++)
        if(p[i].chk)
            ans += min(abs(h - p[i].x) + abs(h - p[i].y) + 1, abs(h2 - p[i].x) + abs(h2 - p[i].y) + 1);
    cout << ans;*/
}


int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    Input();
}

#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...