# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
27604 | 2017-07-13T09:10:44 Z | TAMREF | Palembang Bridges (APIO15_bridge) | C++11 | 86 ms | 2800 KB |
#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); } void solve2(){ ll C[205]; for(int i=0;i<N;i++) C[i<<1]=Q[i],C[i<<1|1]=R[i]; sort(C,C+2*N); int x=unique(C,C+2*N)-C; ll add=1e18,tmp; for(int i=0;i<x;i++){ for(int j=i;j<x;j++){ tmp=0; for(int k=0;k<N;k++){ tmp+=min(abs(Q[k]-C[i])+abs(R[k]-C[i]), abs(Q[k]-C[j])+abs(R[k]-C[j])); } add=min(add,tmp); } } ans+=add; } 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(); else solve2(); printf("%lld\n",ans); }
Compilation message
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 0 ms | 2800 KB | Output is correct |
2 | Correct | 0 ms | 2800 KB | Output is correct |
3 | Correct | 0 ms | 2800 KB | Output is correct |
4 | Correct | 0 ms | 2800 KB | Output is correct |
5 | Correct | 0 ms | 2800 KB | Output is correct |
6 | Correct | 0 ms | 2800 KB | Output is correct |
7 | Correct | 0 ms | 2800 KB | Output is correct |
8 | Correct | 0 ms | 2800 KB | Output is correct |
9 | Correct | 0 ms | 2800 KB | Output is correct |
10 | Correct | 0 ms | 2800 KB | Output is correct |
11 | Correct | 0 ms | 2800 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 0 ms | 2800 KB | Output is correct |
2 | Correct | 0 ms | 2800 KB | Output is correct |
3 | Correct | 0 ms | 2800 KB | Output is correct |
4 | Correct | 0 ms | 2800 KB | Output is correct |
5 | Correct | 0 ms | 2800 KB | Output is correct |
6 | Correct | 0 ms | 2800 KB | Output is correct |
7 | Correct | 0 ms | 2800 KB | Output is correct |
8 | Correct | 0 ms | 2800 KB | Output is correct |
9 | Correct | 0 ms | 2800 KB | Output is correct |
10 | Correct | 0 ms | 2800 KB | Output is correct |
11 | Correct | 0 ms | 2800 KB | Output is correct |
12 | Correct | 49 ms | 2800 KB | Output is correct |
13 | Correct | 86 ms | 2800 KB | Output is correct |
14 | Correct | 49 ms | 2800 KB | Output is correct |
15 | Correct | 43 ms | 2800 KB | Output is correct |
16 | Correct | 49 ms | 2800 KB | Output is correct |
17 | Correct | 59 ms | 2800 KB | Output is correct |
18 | Correct | 63 ms | 2800 KB | Output is correct |
19 | Correct | 86 ms | 2800 KB | Output is correct |
20 | Correct | 66 ms | 2800 KB | Output is correct |
21 | Correct | 66 ms | 2800 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Incorrect | 0 ms | 2800 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Incorrect | 0 ms | 2800 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Incorrect | 0 ms | 2800 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |