Submission #1164254

#TimeUsernameProblemLanguageResultExecution timeMemory
1164254ali2241Palembang Bridges (APIO15_bridge)C++20
22 / 100
26 ms2636 KiB
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define int long long
#define arr2 array<int, 2>
#define arr3 array<int, 3>
#define all(a) a.begin(), a.end()
#define double long double
// #pragma GCC target("avx2")

using namespace std;
using namespace __gnu_pbds;


template<class T> using rb3 = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
template<class T> using mrb3 = tree<T, null_type, less_equal<T>, rb_tree_tag, tree_order_statistics_node_update>;

const int N = 1e5 + 10, M = 998244353;

int cost = 0;

int abc(int a) {
    return (a < 0 ? -a : a);
}

void fun() {
    int k, n;
    cin >> k >> n;
    vector<int> pnt;
    for (int i = 0; i < n; ++i) {
        char a, c;
        int b, d;
        cin >> a >> b >> c >> d;
        if (a == c) {
            cost += abc(d - b);
        }
        else {
            cost++;
            pnt.push_back(b);
            pnt.push_back(d);
        }
    }
    sort(all(pnt));
    if (pnt.size()) {
        int mid = pnt[(pnt.size()) / 2];
        for (int i : pnt) {
            cost += abc(i - mid);
        }
    }
    cout << cost << "\n";
}

int32_t main() {
    ios::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);
    // int tc;
    // cin >> tc;
    // while (tc--)
    fun();
}
#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...