# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
102296 | 2019-03-24T07:24:18 Z | Nicholas_Patrick | Palembang Bridges (APIO15_bridge) | C++17 | 69 ms | 2032 KB |
#include <bits/stdc++.h> using namespace std; int k, n; vector <int> h, w, hw; long long check(int i, int j){ long long tot=0; for(int k = 0;k < n;k ++) tot+=min(abs(h[k]-hw[i])+abs(w[k]-hw[i]),abs(h[k]-hw[j])+abs(w[k]-hw[j])); 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(); sort(hw.begin(), hw.end()); if(k==1){ 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; for(int i = 0;i < n<<1;i ++){ for(int j = 0;j < n<<1;j ++){ curtot=check(i, j); 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 | 2 ms | 384 KB | Output is correct |
2 | Correct | 2 ms | 384 KB | Output is correct |
3 | Correct | 2 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 | 2 ms | 384 KB | Output is correct |
7 | Correct | 3 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 | 2 ms | 384 KB | Output is correct |
11 | Correct | 3 ms | 384 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | 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 | 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 | 2 ms | 384 KB | Output is correct |
11 | Correct | 3 ms | 384 KB | Output is correct |
12 | Correct | 30 ms | 2032 KB | Output is correct |
13 | Correct | 69 ms | 2024 KB | Output is correct |
14 | Correct | 42 ms | 2032 KB | Output is correct |
15 | Correct | 33 ms | 1400 KB | Output is correct |
16 | Correct | 50 ms | 2024 KB | Output is correct |
17 | Correct | 57 ms | 2024 KB | Output is correct |
18 | Correct | 40 ms | 2024 KB | Output is correct |
19 | Correct | 65 ms | 2000 KB | Output is correct |
20 | Correct | 44 ms | 2024 KB | Output is correct |
21 | Correct | 59 ms | 2024 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Incorrect | 3 ms | 384 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Incorrect | 2 ms | 256 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Incorrect | 2 ms | 256 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |