Submission #1031801

# Submission time Handle Problem Language Result Execution time Memory
1031801 2024-07-23T07:29:35 Z _8_8_ Palembang Bridges (APIO15_bridge) C++17
0 / 100
1 ms 348 KB
#include <bits/stdc++.h>
 
using namespace std;
    
typedef long long ll;
const int  N = 1e6 + 21, MOD = (int)1e9+7;

int n,k;
ll res = 0;
array<int,2> a[N];
ll val[N];
ll solve(){
    vector<pair<int,int>> sc;
    for(int i = 1;i <= n;i++){
        sc.push_back({a[i][0],0});
        sc.push_back({a[i][0],1});
    }
    sort(sc.begin(),sc.end());
    ll sum = 0,col = 0;
    for(int i = 0;i < (int)sc.size();i++){
        val[i] = (sc[i].first * 1ll * col) - sum;
        if(sc[i].second == 1){
            col++;
            sum += sc[i].first;
        }
    }
    col = sum =0 ;
    ll res = 1e18;
    for(int i = (int)sc.size() - 1;i >= 0;i--){
        val[i] += sum - (sc[i].first * 1ll * col);
        if(sc[i].second == 0){
            col++;
            sum += sc[i].first;
        }
        res = min(res,val[i]);
    }
    return res;
}
void test() {
    cin >> k >> n;
    int _i = 0;
    for(int i = 1;i <= n;i++) {
        char x,y;
        int l,r;
        cin >> x >> l >> y >> r;
        if(l > r){
            swap(l,r);
            swap(x,y);
        }
        res += (r - l);
        if(x == y){
            continue;
        }
        a[++_i] = {l,r};
    }
    n = _i;
    if(k == 1){
        cout << res + solve();
        return;
    }
}
int main() {
    ios_base::sync_with_stdio(false);cin.tie(0);
    int t = 1; 
    // cin >> t;
    while(t--) {
        test();
    }
}
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 344 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 1 ms 344 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 1 ms 344 KB Output isn't correct
2 Halted 0 ms 0 KB -