이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
#define pb push_back
#define faster ios::sync_with_stdio(0), cin.tie(0), cout.tie(0)
#define pii pair<int, int>
const int MAX_N=2e5+25;
ll res = 0;
ll k, n;
vector<ll> fi, sec;
set<ll> s;
ll suf[MAX_N];
ll pre[MAX_N];
void solve() {
sort(fi.begin(), fi.end());
sort(sec.begin(), sec.end());
for(int i = fi.size(); i >= 1; i--) {
suf[i] = suf[i + 1] + fi[i - 1];
}
for(int i = 0; i < sec.size(); i++) {
pre[i + 1] = sec[i] + pre[i];
}
ll mini = 1e18;
for(auto x : s) {
ll sum = 0;
int pos = upper_bound(fi.begin(), fi.end(), x) - fi.begin() + 1;
sum += suf[pos] - ((fi.size() - pos + 1) * x);
pos = lower_bound(sec.begin(), sec.end(), x) - sec.begin();
sum += (pos * x) - pre[pos];
mini = min(sum, mini);
}
cout << res + 2 * mini;
}
void input() {
cin >> k >> n;
for(int i = 1; i <= n; i++) {
char a, b;
ll x, y;
cin >> a >> x >> b >> y;
res += abs(x - y);
if(a != b) {
res++;
fi.pb(min(x, y));
sec.pb(max(x, y));
s.insert(x);
s.insert(y);
}
}
}
int main() {
faster;
input();
solve();
}
컴파일 시 표준 에러 (stderr) 메시지
bridge.cpp: In function 'void solve()':
bridge.cpp:28:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
28 | for(int i = 0; i < sec.size(); i++) {
| ~~^~~~~~~~~~~~
# | 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... |