Submission #1029504

# Submission time Handle Problem Language Result Execution time Memory
1029504 2024-07-21T00:11:59 Z ArthuroWich Palembang Bridges (APIO15_bridge) C++17
0 / 100
1 ms 348 KB
#include <bits/stdc++.h>
using namespace std;
#define int long long int
void solve() {
    int k, n, extra = 0, ans = 0;
    cin >> k >> n;
    vector<pair<int, int>> a;
    for (int i = 0; i < n; i++) {
        char p, q;
        int s, t;
        cin >> p >> s >> q >> t;
        if (p == q) {
            extra += abs(s-t);
            continue;
        } 
        if (p == 'A') {
            a.push_back({s, t});
        } else {
            a.push_back({t, s});
        }
    }
    n = a.size();
    sort(a.begin(), a.end());
    if (k == 1) {
        vector<int> b;
        for (int i = 0; i < n; i++) {
            b.push_back(a[i].first);
            b.push_back(a[i].second);
        }
        sort(b.begin(), b.end());
        int med = 0;
        if (b.size()) {
            med = b[b.size()/2];
        }
        for (auto [i, j] : a) {
            ans += abs(i-med);
            ans += abs(j-med);
        }
        cout << ans+extra << endl;
    } else {
        cout << 0 << endl;
    }
}
int32_t main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    int t;
    t = 1;
    while(t--) {
        solve();
    }
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 1 ms 344 KB Output is correct
3 Incorrect 0 ms 348 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Incorrect 0 ms 348 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 348 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 344 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 348 KB Output isn't correct
2 Halted 0 ms 0 KB -