Submission #736000

# Submission time Handle Problem Language Result Execution time Memory
736000 2023-05-05T06:14:27 Z ReLice Palembang Bridges (APIO15_bridge) C++14
0 / 100
1 ms 212 KB
#include <bits/stdc++.h>
#define ll int
#define ld long double
#define pb push_back
#define endl "\n"
#define fr first
#define sc second
#define sz size()
#define bc back()
using namespace std;

#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
#define ordered_set tree<ll, null_type,less_equal<ll>, rb_tree_tag,tree_order_statistics_node_update>
void fre(string s){freopen((s+".in").c_str(),"r",stdin);freopen((s+".out").c_str(),"w",stdout);}
void start(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
}
const ll inf=1e9+7;
const ll mod=1e9+7;
const ll N=1e5+7;
ll n,l,r;
map<ll,ll> mp;
ordered_set os,oe;
ll pre[N],prs[N];
void solve(){
    ll i,j,q,sum=0,ans=inf,mn=inf,m;
    ll a,b,c,t,k;
    cin>>k>>n;
    vector <ll> v;
    vector <pair<ll,ll>> v2;
    char ch,ch2;
    for(i=0;i<n;i++){
        cin>>ch>>a>>ch2>>b;
        sum+=abs(a-b)+1;
        mn=min(mn,min(a,b));
        if(ch==ch2) {sum--;continue;}
        if(a>b) swap(a,b);
        v2.pb({a,b});
        if(mp[a]==0) v.pb(a);
        mp[a]++;
        if(mp[b]==0) v.pb(b);
        mp[b]++;
    }
    sort(v.begin(),v.end());
    n=v.sz;
    for(i=0;i<v2.sz;i++){
        v2[i].fr-=v[0];
        v2[i].sc-=v[0];
    }
    for(i=n-1;i>=0;i--){
        v[i]-=v[0];
    }
    for(i=0;i<v2.sz;i++){
        os.insert(v2[i].fr);
        oe.insert(v2[i].sc);
    }
    ll c1=v[0],c2=v[0];
    for(i=0;i<v2.sz;i++){
        ll cur=*(oe.find_by_order(i));
        if(v[c1]<cur){
            while(v[c1]<cur) {
                c1++;
                pre[c1]=pre[c1-1];
            }
            pre[c1]=cur;
            if(c1>0)pre[c1]=pre[c1-1]+cur;
        }
        else pre[c1]+=cur;
        cur=*(os.find_by_order(i));
        if(v[c2]<cur){
            while(v[c2]<cur) {
                c2++;
                prs[c2]=prs[c2-1];
            }
            prs[c2]=cur;
            if(c2>0)prs[c2]=prs[c2-1]+cur;
        }
        else prs[c2]+=cur;
        if(i==v2.sz-1){
            while(c2<n){
                c2++;
                prs[c2]=prs[c2-1];
            }
        }
    }
    if(k==1){
        for(i=0;i<n;i++){
            ans=min(ans,(ll)(v[i]*oe.order_of_key(v[i])-pre[i-1] + prs[n-1]-prs[i]-v[i]*( os.sz-os.order_of_key(v[i]+1) ) ) );
        }
        cout<<ans*2+sum<<endl;
    }
    else{
        
    }
}
signed main(){
    //start();
    //fre("");
    ll t=1;
    //cin>>t;
    while(t--) solve();
}
/*
1 5
B 0 A 4
B 1 B 3
A 5 B 7
B 2 A 6
B 1 A 7
*/

Compilation message

bridge.cpp: In function 'void solve()':
bridge.cpp:50:14: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   50 |     for(i=0;i<v2.sz;i++){
      |              ^
bridge.cpp:57:14: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   57 |     for(i=0;i<v2.sz;i++){
      |              ^
bridge.cpp:62:14: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   62 |     for(i=0;i<v2.sz;i++){
      |              ^
bridge.cpp:83:13: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   83 |         if(i==v2.sz-1){
      |            ~^~~~~~~~~
bridge.cpp:30:10: warning: unused variable 'j' [-Wunused-variable]
   30 |     ll i,j,q,sum=0,ans=inf,mn=inf,m;
      |          ^
bridge.cpp:30:12: warning: unused variable 'q' [-Wunused-variable]
   30 |     ll i,j,q,sum=0,ans=inf,mn=inf,m;
      |            ^
bridge.cpp:30:35: warning: unused variable 'm' [-Wunused-variable]
   30 |     ll i,j,q,sum=0,ans=inf,mn=inf,m;
      |                                   ^
bridge.cpp:31:12: warning: unused variable 'c' [-Wunused-variable]
   31 |     ll a,b,c,t,k;
      |            ^
bridge.cpp:31:14: warning: unused variable 't' [-Wunused-variable]
   31 |     ll a,b,c,t,k;
      |              ^
bridge.cpp: In function 'void fre(std::string)':
bridge.cpp:16:27: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   16 | void fre(string s){freopen((s+".in").c_str(),"r",stdin);freopen((s+".out").c_str(),"w",stdout);}
      |                    ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~
bridge.cpp:16:64: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   16 | void fre(string s){freopen((s+".in").c_str(),"r",stdin);freopen((s+".out").c_str(),"w",stdout);}
      |                                                         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# 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 212 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 -
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 212 KB Output isn't correct
2 Halted 0 ms 0 KB -