Submission #837152

#TimeUsernameProblemLanguageResultExecution timeMemory
837152vjudge1Palembang Bridges (APIO15_bridge)C++17
22 / 100
34 ms3668 KiB
#include <bits/stdc++.h>
using namespace std;
#define futaba ios_base::sync_with_stdio(false); cin.tie(NULL);
#define rio return 0;
#define ll long long
#define fi first
#define se second

// Fun things are fun. //

int main() {
    /* freopen(".txt", "r", stdin);
    freopen(".txt", "w", stdout); */
    futaba
    ll k, n;
    cin >> k >> n;
    ll ans = 0;
    if(k == 1) {
        vector<ll> v;
        vector<pair<ll, ll>> v2;
        while(n--) {
            char p;
            cin >> p;
            ll s;
            cin >> s;
            char q;
            cin >> q;
            ll t;
            cin >> t;
            if(p == q) ans += abs(s - t);
            else {
                v.push_back(s);
                v.push_back(t);
                v2.push_back({s, t});
            }
        }
        if(!v.empty() and !v2.empty()) {
            sort(v.begin(), v.end());
            ll x = v[(int)v.size() / 2];
            for(auto i : v2) ans += (abs(i.fi - x) + abs(i.se - x)) + 1;
        }
        cout << ans << '\n';
    }
    else {
        while(n--) {
            char p;
            cin >> p;
            ll s;
            cin >> s;
            char q;
            cin >> q;
            ll t;
            cin >> t;
        }
        cout << "a\n";
    }
    rio
}
#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...