이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
ll n, k, sm, cnt;
vector<pair<ll, ll>> vec;
vector<ll> l, r, both;
int main(){
cin >> k >> n;
for (ll i = 0; i < n; i ++){
char p, q;
ll s, t;
cin >> p >> s >> q >> t;
if (s > t) swap(s, t);
if (p == q){
cnt++;
sm += t - s;
}
else{
vec.push_back({s, t});
l.push_back(s);
r.push_back(t);
both.push_back(s);
both.push_back(t);
}
}
sort(vec.begin(), vec.end());
sort(l.begin(), l.end());
sort(r.begin(), r.end());
sort(both.begin(), both.end());
ll ans = 1e18;
if (k == 1){
ll prev = 0;
ll after = 0;
for (ll i = 1; i < both.size(); i ++)
after += both[i] - both[0];
ans = min(ans, sm + after + n - cnt);
for (ll i = 1; i < both.size(); i ++){
after -= (both[i] - both[i - 1]) * (both.size() - i);
prev += (both[i] - both[i - 1]) * i;
ans = min(ans, sm + prev + after + n - cnt);
}
cout << ans << endl;
}
}
컴파일 시 표준 에러 (stderr) 메시지
bridge.cpp: In function 'int main()':
bridge.cpp:43:26: warning: comparison of integer expressions of different signedness: 'll' {aka 'long long int'} and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
43 | for (ll i = 1; i < both.size(); i ++)
| ~~^~~~~~~~~~~~~
bridge.cpp:47:26: warning: comparison of integer expressions of different signedness: 'll' {aka 'long long int'} and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
47 | for (ll i = 1; i < both.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... |