Submission #997409

# Submission time Handle Problem Language Result Execution time Memory
997409 2024-06-12T09:19:40 Z doducanh Palembang Bridges (APIO15_bridge) C++14
22 / 100
136 ms 12488 KB
#include<bits/stdc++.h>
using namespace std;
#define ii pair<int,int>
#define fi first
#define se second
int k,n;
long long sumL=0,sumU=0;
vector<ii>v;
multiset<int>low;
multiset<int>up;
long long pref[100005];
bool cmp(ii a,ii b)
{
    return (a.fi+a.se)<(b.fi+b.se);
}
void capnhat(int x)
{
    int val;
    if(low.size()==0)val=0;
    else val=*low.rbegin();
    if(x<=val){
        low.insert(x);
        sumL+=x;
    }
    else{
        up.insert(x);
        sumU+=x;
    }
    if(low.size()>up.size()+1){
        up.insert(*low.rbegin());
        sumU+=(*low.rbegin());
        sumL-=(*low.rbegin());
        low.erase(low.find(*low.rbegin()));
    }
    else if(up.size()>low.size()){
        low.insert(*up.begin());
        sumL+=(*up.begin());
        sumU-=(*up.begin());
        up.erase(up.begin());
    }
}
main()
{
    cin>>k>>n;
    long long delt=0;
    for(int i=1;i<=n;i++){
        char a,b;
        int x,y;
        cin>>a>>x>>b>>y;
        if(a==b){
            delt+=abs(x-y);
        }
        else{
            v.push_back({x,y});
        }
    }
    sort(v.begin(),v.end(),cmp);
    long long ans=LLONG_MAX;
    for(int i=0;i<v.size();i++){
        capnhat(v[i].fi);
        capnhat(v[i].se);
        pref[i]=sumU-sumL;

    }
    ans=min(ans,sumU-sumL+(long long)v.size());
    if(k==2){
        sumL=0,sumU=0;
        for(int x:low)low.erase(x);
        for(int x:up)up.erase(x);
        for(int i=v.size();i>0;i--){
            capnhat(v[i].fi);
            capnhat(v[i].se);
            ans=min(ans,pref[i-1]+sumU-sumL+(long long)v.size());
        }
    }

    cout<<ans+delt;
    return 0;
}

Compilation message

bridge.cpp:42:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
   42 | main()
      | ^~~~
bridge.cpp: In function 'int main()':
bridge.cpp:59:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   59 |     for(int i=0;i<v.size();i++){
      |                 ~^~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
7 Correct 1 ms 348 KB Output is correct
8 Correct 1 ms 348 KB Output is correct
9 Correct 2 ms 348 KB Output is correct
10 Correct 1 ms 344 KB Output is correct
11 Correct 1 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 1 ms 452 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Correct 1 ms 344 KB Output is correct
7 Correct 1 ms 348 KB Output is correct
8 Correct 1 ms 348 KB Output is correct
9 Correct 1 ms 344 KB Output is correct
10 Correct 1 ms 360 KB Output is correct
11 Correct 1 ms 348 KB Output is correct
12 Correct 67 ms 12008 KB Output is correct
13 Correct 136 ms 12476 KB Output is correct
14 Correct 99 ms 10952 KB Output is correct
15 Correct 73 ms 7884 KB Output is correct
16 Correct 83 ms 12288 KB Output is correct
17 Correct 107 ms 12480 KB Output is correct
18 Correct 85 ms 12488 KB Output is correct
19 Correct 104 ms 12488 KB Output is correct
20 Correct 94 ms 12484 KB Output is correct
21 Correct 100 ms 12484 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Runtime error 1 ms 348 KB Execution killed with signal 11
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Runtime error 1 ms 348 KB Execution killed with signal 11
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Runtime error 1 ms 348 KB Execution killed with signal 11
4 Halted 0 ms 0 KB -