Submission #1037738

# Submission time Handle Problem Language Result Execution time Memory
1037738 2024-07-29T07:32:45 Z stdfloat Palembang Bridges (APIO15_bridge) C++17
0 / 100
1 ms 348 KB
#include <bits/stdc++.h>
using namespace std;

using ll = long long;

#define int long long

#define ff  first
#define ss  second
#define pii pair<int, int>

ll f(int x, vector<pii> &v) {
    ll sm = 0;
    for (auto i : v) sm += abs(i.ff - x) + 1 + abs(i.ss - x);

    return sm;
}

int32_t main() {
    ios::sync_with_stdio(false); cin.tie(nullptr);

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

    ll sm = 0;
    vector<pii> v;
    for (int i = 0; i < n; i++) {
        char p, q;
        int s, t;
        cin >> p >> s >> q >> t;

        if (p == q) sm += abs(t - s);
        else v.push_back({s, t});
    }

    int l = 0, r = (int)1e9;
    while (l <= r) {
        int md = (l + r) >> 1;

        if (f(md, v) >= f(md + 1, v)) l = md + 1;
        else r = md - 1;
    }

    cout << sm + f(max(0LL, l - 1), v);
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Incorrect 1 ms 348 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Incorrect 1 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 Correct 0 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 Correct 0 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 -