이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define inf 0x3F3F3F3F3F3F3F3F
signed main()
{
ios_base::sync_with_stdio(0);
cin.tie(0);
int k, n, S = 0;
cin >> k >> n;
vector<int> id, p, s;
for (int i = 0; i < n; i++)
{
char a, b;
int l, r;
cin >> a >> l >> b >> r;
if (l > r) swap(l, r);
if (a == b) S += r - l;
else id.push_back(l), id.push_back(r);
}
if (id.empty())
{
cout << S << '\n';
return 0;
}
sort(id.begin(), id.end());
p = s = id;
for (int i = 1; i < p.size(); i++) p[i] += p[i - 1];
for (int i = (int)s.size() - 2; i >= 0; i--) s[i] += s[i + 1];
s.push_back(0);
int res = inf;
for (int i = 0; i < id.size(); i++)
{
res = min(res, s[i + 1] - p[i] + id[i] * (2 * (i + 1) - (int)id.size()));
}
cout << res + S + (int)id.size() / 2 << '\n';
}
컴파일 시 표준 에러 (stderr) 메시지
bridge.cpp: In function 'int main()':
bridge.cpp:31:21: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
31 | for (int i = 1; i < p.size(); i++) p[i] += p[i - 1];
| ~~^~~~~~~~~~
bridge.cpp:35:21: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
35 | for (int i = 0; i < id.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... |