Submission #971778

# Submission time Handle Problem Language Result Execution time Memory
971778 2024-04-29T09:25:37 Z Halym2007 Palembang Bridges (APIO15_bridge) C++17
0 / 100
1 ms 2396 KB
#include "bits/stdc++.h"
#define ll long long int
#define pb push_back
#define ff first
#define ss second
#define sz size()

const int N = 2e5 + 1;

using namespace std;

int k, n, vis[N], cnt;

ll mn = 1e15, sum, p[N];

pair <char,int> a[N], b[N];

vector <int> v;

int main(){
    ios::sync_with_stdio(false); cin.tie(nullptr);
    cin >> k >> n;
    for(int i = 1; i <= n; i++){
    cin >> a[i].ff >> a[i].ss >> b[i].ff >> b[i].ss;
    if(a[i].ff != b[i].ff){
    v.pb(b[i].ss);
    v.pb(a[i].ss);
            cnt++;
    }
    else sum += abs(a[i].ss-b[i].ss);
    }
    sort(v.begin(), v.end());
    for(int i = 0; i < (int)v.sz; i++){
    p[i+1] = v[i] + p[i];
    }
    for(int i = 0; i < (int)v.sz; i++){
    ll x;
        x = i*v[i] - p[i];
        x += p[v.sz] - p[i+1] - (v.sz-i-1)*v[i];
        mn = min(mn,x);
    }
    cout << mn + sum + cnt;
}
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 2396 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 2396 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 2396 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 2396 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 2396 KB Output isn't correct
2 Halted 0 ms 0 KB -