# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
17346 | 2015-11-22T09:12:04 Z | comet | Palembang Bridges (APIO15_bridge) | C++ | 0 ms | 4240 KB |
#include <cstdio> #include <algorithm> using namespace std; typedef long long ll; int K,N; ll base; ll a[200010],sum[200010],sz; int main(){ // freopen("bridge.in","r",stdin); scanf("%d%d ",&K,&N); char tx,ty; ll x,y; for(int i=0;i<N;i++){ scanf("%c %lld %c %lld ",&tx,&x,&ty,&y); // printf("%c %lld %c %lld\n",tx,x,ty,y); if(tx==ty){ base+=abs(x-y); }else{ a[++sz]=x; a[++sz]=y; base++; } } sort(a+1,a+sz+1); a[sz+1]=-1; for(int i=1;i<=sz;i++){ sum[i]=sum[i-1]+a[i]; } /* for(int i=1;i<=sz;i++){ printf("%lld ",a[i]); } puts(""); */ ll ans=1e18; for(ll i=1;i<=sz;i++){ x=a[i]; while(a[i+1]==x)i++; // printf("%lld : %lld - %lld\n",i,x,sum[sz]-2ll*sum[i]+(2ll*i-sz)*x); ans=min(ans,sum[sz]-2ll*sum[i]+(2ll*i-sz)*x); } printf("%lld\n",ans+base); }
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 0 ms | 4240 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 0 ms | 4240 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 0 ms | 4240 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 0 ms | 4240 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 0 ms | 4240 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |