Submission #1037741

# Submission time Handle Problem Language Result Execution time Memory
1037741 2024-07-29T07:33:39 Z stdfloat Palembang Bridges (APIO15_bridge) C++17
0 / 100
0 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});
    }

    ll ans = LLONG_MAX;
    for (auto i : v) ans = min({ans, f(i.ff, v), f(i.ss, v)});

    cout << sm + ans;
}
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 348 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 -
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 348 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 -
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 348 KB Output isn't correct
2 Halted 0 ms 0 KB -