Submission #27259

#TimeUsernameProblemLanguageResultExecution timeMemory
27259TAMREFPalembang Bridges (APIO15_bridge)C++11
22 / 100
76 ms2800 KiB
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int Q[100005], R[100005], K, N;
ll ans, ans2;
inline ll pro(int x){
    ll u=0;
    for(int i=0;i<N;i++){
        u+=abs((ll)x-Q[i])+abs((ll)x-R[i]);
    }
    return u;
}
void solve1(){
    int p=0,q,r,s=1e9;
    while(p<s){
        q=p+(s-p)/3;
        r=s-(s-p)/3;
        if(pro(q)<=pro(r)) s=r-1;
        else p=q+1;
    }
    ans+=pro(p);
}
int main(){
    scanf("%d %d",&K,&N);
    char u,v;
    for(int i=0;i<N;i++){
        getchar();
        u=getchar();
        scanf(" %d ",&Q[i]);
        v=getchar();
        scanf(" %d",&R[i]);
        if(u==v){
            ans+=abs(Q[i]-R[i]);
            --i;--N;
        }else{
            ++ans;
            if(u=='B') swap(Q[i],R[i]);
        }
    } ans2=ans;
    if(K==1) solve1();
    printf("%lld\n",ans);
}

Compilation message (stderr)

bridge.cpp: In function 'int main()':
bridge.cpp:24:25: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d %d",&K,&N);
                         ^
bridge.cpp:29:28: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf(" %d ",&Q[i]);
                            ^
bridge.cpp:31:27: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf(" %d",&R[i]);
                           ^
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...