# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
102288 | 2019-03-24T06:48:06 Z | Nicholas_Patrick | Palembang Bridges (APIO15_bridge) | C++17 | 63 ms | 2068 KB |
#include <bits/stdc++.h> using namespace std; int k, n; vector <int> h, w, hw; int movementI, movementJ; long long check(int i, int j){ long long tot=0; movementI=0, movementJ=0; int throughI, throughJ; for(int k = 0;k < n;k ++){ throughI=abs(h[k]-hw[i])+abs(w[k]-hw[i]); throughJ=abs(h[k]-hw[j])+abs(w[k]-hw[j]); if(throughI<throughJ){ if(hw[i]<h[k]) movementI++; if(hw[i]>w[k]) movementI--; tot+=throughI; }else{ if(hw[j]<h[k]) movementJ++; if(hw[j]>w[k]) movementJ--; tot+=throughJ; } } return tot; } int main(){ scanf("%d %d", &k, &n); bool cross;int s, t; long long tot1=0; char c; while(n--){ while(true){ c=getchar(); if(c=='A'){ cross=false; break; }else if(c=='B'){ cross=true; break; } } scanf("%d", &s); while(true){ c=getchar(); if(c=='A'){ break; }else if(c=='B'){ cross^=true; break; } } scanf("%d", &t); if(cross){ if(s>t) swap(s, t); h.push_back(s); w.push_back(t); hw.push_back(s); hw.push_back(t); tot1++; }else{ tot1+=abs(t-s); } } n=h.size(); if(k==1){ sort(hw.begin(), hw.end()); n=hw.size(); long long tot2=0; k=n>>1; for(int i = 0;i < n;i ++) tot2+=abs(hw[k]-hw[i]); printf("%lld\n", tot1+tot2); }else if(k==2){ long long tot2=200000000000000; long long curtot; long long up, down, left, right; int i=(n<<1)/3, j=(n<<2)/3; for(int l = 0;l < 40;l ++){ curtot=check(i, j); i+=movementI; j+=movementJ; tot2=min(tot2, curtot); } for(int l = 0;l < 40;l ++){ curtot=check(i, j); if(l&1) i+=movementI; else j+=movementJ; tot2=min(tot2, curtot); } printf("%lld\n", tot1+tot2); } return 0; } /* 2 5 B 0 A 4 B 1 B 3 A 5 B 7 B 2 A 6 B 1 A 7 */
Compilation message
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 3 ms | 384 KB | Output is correct |
2 | Correct | 3 ms | 384 KB | Output is correct |
3 | Correct | 3 ms | 384 KB | Output is correct |
4 | Correct | 2 ms | 384 KB | Output is correct |
5 | Correct | 3 ms | 384 KB | Output is correct |
6 | Correct | 3 ms | 384 KB | Output is correct |
7 | Correct | 2 ms | 384 KB | Output is correct |
8 | Correct | 3 ms | 384 KB | Output is correct |
9 | Correct | 3 ms | 384 KB | Output is correct |
10 | Correct | 3 ms | 384 KB | Output is correct |
11 | Correct | 3 ms | 384 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 2 ms | 384 KB | Output is correct |
2 | Correct | 3 ms | 384 KB | Output is correct |
3 | Correct | 2 ms | 384 KB | Output is correct |
4 | Correct | 3 ms | 384 KB | Output is correct |
5 | Correct | 2 ms | 384 KB | Output is correct |
6 | Correct | 3 ms | 384 KB | Output is correct |
7 | Correct | 3 ms | 384 KB | Output is correct |
8 | Correct | 2 ms | 384 KB | Output is correct |
9 | Correct | 3 ms | 384 KB | Output is correct |
10 | Correct | 3 ms | 384 KB | Output is correct |
11 | Correct | 3 ms | 384 KB | Output is correct |
12 | Correct | 38 ms | 2032 KB | Output is correct |
13 | Correct | 62 ms | 2024 KB | Output is correct |
14 | Correct | 44 ms | 2024 KB | Output is correct |
15 | Correct | 37 ms | 1364 KB | Output is correct |
16 | Correct | 62 ms | 2024 KB | Output is correct |
17 | Correct | 55 ms | 2012 KB | Output is correct |
18 | Correct | 60 ms | 2068 KB | Output is correct |
19 | Correct | 56 ms | 2024 KB | Output is correct |
20 | Correct | 63 ms | 2028 KB | Output is correct |
21 | Correct | 59 ms | 2024 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 2 ms | 384 KB | Output is correct |
2 | Correct | 2 ms | 384 KB | Output is correct |
3 | Correct | 3 ms | 256 KB | Output is correct |
4 | Incorrect | 2 ms | 256 KB | Output isn't correct |
5 | Halted | 0 ms | 0 KB | - |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 2 ms | 256 KB | Output is correct |
2 | Correct | 2 ms | 256 KB | Output is correct |
3 | Correct | 3 ms | 384 KB | Output is correct |
4 | Incorrect | 3 ms | 256 KB | Output isn't correct |
5 | Halted | 0 ms | 0 KB | - |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 2 ms | 384 KB | Output is correct |
2 | Correct | 3 ms | 384 KB | Output is correct |
3 | Correct | 3 ms | 384 KB | Output is correct |
4 | Incorrect | 4 ms | 256 KB | Output isn't correct |
5 | Halted | 0 ms | 0 KB | - |