# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
682519 | 79brue | Palembang Bridges (APIO15_bridge) | C++17 | 62 ms | 6316 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int n, k;
ll base, ans;
ll a[100002], b[100002];
int main(){
scanf("%d %d", &k, &n);
for(int i=1; i<=n; i++){
char C1, C2;
int X1, X2;
scanf(" %c %d %c %d", &C1, &X1, &C2, &X2);
if(C1==C2) base += abs(X1-X2), n--, i--;
else a[i] = X1, b[i] = X2;
}
if(n==0){
printf("%lld", base);
return 0;
}
if(k==1){
vector<ll> vec;
for(int i=1; i<=n; i++) vec.push_back(a[i]), vec.push_back(b[i]);
sort(vec.begin(), vec.end());
ans = 1e18;
ll lsum = 0, lcnt = 0, rsum = accumulate(vec.begin(), vec.end(), 0LL), rcnt = (int)vec.size();
for(int i=0; i<n*2; i++){
rsum -= vec[i], rcnt--;
ans = min(ans, (lcnt * vec[i] - lsum) + (rsum - rcnt * vec[i]) + n);
lsum += vec[i], lcnt++;
}
printf("%lld", ans+base);
return 0;
}
}
컴파일 시 표준 에러 (stderr) 메시지
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |