Submission #738672

# Submission time Handle Problem Language Result Execution time Memory
738672 2023-05-09T11:02:58 Z Alihan_8 Palembang Bridges (APIO15_bridge) C++17
0 / 100
1 ms 320 KB
#include <bits/stdc++.h>

using namespace std;

#define all(x) x.begin(), x.end()
#define pb push_back
#define ln '\n'
#define int long long

template <class _T>
bool chmin(_T &x, const _T &y){
    bool flag = false;
    if ( x > y ){
        x = y; flag |= true;
    }
    return flag;
}

template <class _T>
bool chmax(_T &x, const _T &y){
    bool flag = false;
    if ( x < y ){
        x = y; flag |= true;
    }
    return flag;
}

signed main(){
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);

    int k, n; cin >> k >> n;
    if ( k == 1 ){
        int C = 0;
        vector <int> p;
        for ( int i = 0; i < n; i++ ){
            char a, b;
            int x, y;
            cin >> a >> x >> b >> y;
            if ( a == b ){
                C += abs(x - y);
            }
            else{
                p.pb(x), p.pb(y);
            }
        }
        sort(all(p));
        int sz = (int)p.size(), Mn = 1e18;
        if ( !sz ) Mn = 9;
        int pref = 0, suff = accumulate(all(p), 0ll);
        for ( int i = 0; i < sz; i++ ){
            suff -= p[i];
            chmin(Mn, i * p[i] - pref + suff - (sz - i - 1) * p[i]);
            pref += p[i];
        }
        cout << Mn + C + sz / 2 << ln;
        return 0;
    }

    cout << '\n';
}
/*

1 5
B 0 A 4
B 1 B 3
A 5 B 7
B 2 A 6
B 1 A 7

*/
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 212 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 212 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 212 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 320 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 212 KB Output isn't correct
2 Halted 0 ms 0 KB -