# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
766392 | 2023-06-25T15:35:13 Z | ivopav | Palembang Bridges (APIO15_bridge) | C++17 | 69 ms | 4280 KB |
#include <bits/stdc++.h> using namespace std; int main(){ long long int n; long long int k; cin >> k >> n; long long int isp=0; vector<pair<long long int,long long int>> lis={}; for (long long int i=0;i<n;i++){ char prvgdje; long long int prv; char drugdje; long long int dru; cin >> prvgdje >> prv >> drugdje >> dru; if (prvgdje==drugdje){ isp+=abs(prv-dru); } else { lis.push_back({prv,dru}); } } long long int poc=0; long long int kra=1000000001; long long int sre=kra/2; while (poc<sre){ long long int zbr1=0; long long int zbr2=0; for (long long int i=0;i<lis.size();i++){ zbr1+=abs(sre-lis[i].first)+abs(sre-lis[i].second); zbr2+=abs(sre+1-lis[i].first)+abs(sre+1-lis[i].second); } if (zbr1==zbr2){ break; } else if (zbr1<zbr2){ kra=sre; } else { poc=sre; } sre=(poc+kra)/2; } long long int zbr1=0; long long int zbr2=0; long long int zbr3=0; for (long long int i=0;i<lis.size();i++){ zbr1+=abs((sre-1)-lis[i].first)+abs((sre-1)-lis[i].second); zbr2+=abs((sre)-lis[i].first)+abs((sre)-lis[i].second); zbr3+=abs((sre+1)-lis[i].first)+abs((sre+1)-lis[i].second); } // cout << isp << " " << sre << " " << zbr1 << " " << zbr2 << " " << zbr3 << "\n"; cout << isp+min(zbr1,min(zbr2,zbr3))+lis.size() << "\n"; }
Compilation message
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 0 ms | 212 KB | Output is correct |
2 | Correct | 0 ms | 212 KB | Output is correct |
3 | Correct | 1 ms | 212 KB | Output is correct |
4 | Correct | 1 ms | 212 KB | Output is correct |
5 | Correct | 1 ms | 212 KB | Output is correct |
6 | Correct | 1 ms | 212 KB | Output is correct |
7 | Correct | 1 ms | 212 KB | Output is correct |
8 | Correct | 1 ms | 212 KB | Output is correct |
9 | Correct | 1 ms | 212 KB | Output is correct |
10 | Correct | 1 ms | 212 KB | Output is correct |
11 | Correct | 1 ms | 212 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 0 ms | 212 KB | Output is correct |
2 | Correct | 0 ms | 212 KB | Output is correct |
3 | Correct | 1 ms | 212 KB | Output is correct |
4 | Correct | 1 ms | 212 KB | Output is correct |
5 | Correct | 1 ms | 212 KB | Output is correct |
6 | Correct | 1 ms | 212 KB | Output is correct |
7 | Correct | 1 ms | 212 KB | Output is correct |
8 | Correct | 1 ms | 212 KB | Output is correct |
9 | Correct | 1 ms | 212 KB | Output is correct |
10 | Correct | 1 ms | 212 KB | Output is correct |
11 | Correct | 1 ms | 212 KB | Output is correct |
12 | Correct | 39 ms | 2492 KB | Output is correct |
13 | Correct | 69 ms | 4280 KB | Output is correct |
14 | Correct | 47 ms | 3552 KB | Output is correct |
15 | Correct | 44 ms | 2720 KB | Output is correct |
16 | Correct | 53 ms | 3620 KB | Output is correct |
17 | Correct | 65 ms | 4196 KB | Output is correct |
18 | Correct | 57 ms | 3924 KB | Output is correct |
19 | Correct | 68 ms | 4240 KB | Output is correct |
20 | Correct | 63 ms | 3852 KB | Output is correct |
21 | Correct | 65 ms | 4036 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 0 ms | 212 KB | Output is correct |
2 | Correct | 0 ms | 212 KB | Output is correct |
3 | Incorrect | 0 ms | 212 KB | Output isn't correct |
4 | Halted | 0 ms | 0 KB | - |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 0 ms | 212 KB | Output is correct |
2 | Correct | 0 ms | 212 KB | Output is correct |
3 | Incorrect | 0 ms | 212 KB | Output isn't correct |
4 | Halted | 0 ms | 0 KB | - |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 0 ms | 212 KB | Output is correct |
2 | Correct | 0 ms | 212 KB | Output is correct |
3 | Incorrect | 0 ms | 212 KB | Output isn't correct |
4 | Halted | 0 ms | 0 KB | - |