| # | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
|---|---|---|---|---|---|---|---|
| 884831 | Hakiers | Palembang Bridges (APIO15_bridge) | C++17 | 2101 ms | 4296 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
constexpr int MAXN = 1e5 + 7;
constexpr ll oo = 2e18;
ll total;
pair<ll, ll> T[MAXN];
vector<ll> Z;
int n, k;
ll check(ll l, ll r){
ll res = 0;
for(int i = 1; i <= n; i++){
if(T[i].first == -1) continue;
if(T[i].first <= l && l <= T[i].second) continue;
if(T[i].first <= r && r <= T[i].second) continue;
ll cost1 = min(abs(T[i].first - l), abs(T[i].second-l));
ll cost2 = min(abs(T[i].first - r), abs(T[i].second-r));
res += 2*min(cost1, cost2);
}
return res;
}
ll solve(){
ll res = oo;
if(k == 2){
for(int i = 0; i < Z.size(); i++)
for(int j = i; j < Z.size(); j++)
res = min(res, check(Z[i], Z[j]));
}
else {
for(int j = 0; j < Z.size(); j++)
res = min(res, check(Z[j], Z[j]));
}
return res;
}
int main(){
cin >> k >> n;
for(int i = 1; i <= n; i++){
char x, y;
ll a, b;
cin >> x >> a >> y >> b;
if(b < a) swap(a, b);
if(x != y){
total += (b-a+1);
T[i] = {a, b};
}
else{
total += (b-a);
T[i] = {-1, -1};
}
Z.push_back(a);
Z.push_back(b);
}
sort(Z.begin(), Z.end());
cout << total + solve() << "\n";
}컴파일 시 표준 에러 (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... | ||||
