Submission #497682

#TimeUsernameProblemLanguageResultExecution timeMemory
497682clamsPalembang Bridges (APIO15_bridge)C++17
0 / 100
1 ms332 KiB
#include <bits/stdc++.h>
using namespace std;
#define int long long

signed main() {
    ios::sync_with_stdio(0);
    cin.tie(0);

    int k, n;
//    cin >> k >> n;
    cin >> n >> k;

    vector<pair<pair<char, int>, pair<char, int>>> a(n);
    vector<int> pos;

    for (int i = 0; i < n; i++) {
        cin >> a[i].first.first >> a[i].first.second;
        cin >> a[i].second.first >> a[i].second.second;

        if (a[i].first.first != a[i].second.first) {
            pos.push_back(a[i].first.second);
            pos.push_back(a[i].second.second);
        }
    }

    sort(pos.begin(), pos.end());

    int median = pos[(int)pos.size() / 2];

    int ans = 0;
    for (int i = 0; i < n; i++) {
        if (a[i].first.first != a[i].second.first) {
            ans += abs(median - a[i].first.second);
            ans += abs(median - a[i].second.second);
            ans += 1;
        } else {
            ans += abs(a[i].first.second - a[i].second.second);
        }
    }

    cout << ans;
}

/*
1 5
B 0 A 4
B 1 B 3
A 5 B 7
B 2 A 6
B 1 A 7
*/
#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...