| # | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
|---|---|---|---|---|---|---|---|
| 43681 | RezwanArefin01 | Palembang Bridges (APIO15_bridge) | C++14 | 2 ms | 508 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> ii;
struct ds {
vector<int> a;
vector<ll> s;
void add(int x) { a.push_back(x); }
void init() {
sort(a.begin(), a.end());
s.resize(a.size());
s[0] = a[0];
for(int i = 1; i < a.size(); i++) {
s[i] = s[i - 1] + a[i];
}
}
ll get(ll x) {
int lo = 0, hi = a.size() - 1, idx = -1;
while(lo <= hi) {
int mid = lo + hi >> 1;
if(a[mid] <= x) idx = mid, lo = mid + 1;
else hi = mid - 1;
}
if(idx == -1) {
return s[a.size() - 1] - a.size() * x;
} else {
ll ret = x * (idx + 1) - s[idx];
ret += s[a.size() - 1] - s[idx] - (a.size() - 1 - idx) * x;
return ret;
}
}
} A, B;
int main(int argc, char const *argv[]) {
#ifdef LOCAL_TESTING
freopen("in", "r", stdin);
#endif
int k, n; cin >> k >> n; if(k != 1) return 0;
vector<int> pos;
ll ans = 0;
for(int i = 0; i < n; i++) {
char p, q; int t, s;
cin >> p >> s >> q >> t;
if(p == q) ans += abs(s - t);
else {
A.add(s), B.add(t);
pos.push_back(s);
pos.push_back(t);
}
}
A.init(); B.init();
// sort(pos.begin(), pos.end());
// pos.erase(unique(pos.begin(), pos.end()), pos.end());
ll Min = 1e18;
for(int p : pos) {
Min = min(Min, A.get(p) + B.get(p));
}
cout << Min + A.a.size() + ans << endl;
}컴파일 시 표준 에러 (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... | ||||
