#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);
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;
}
}
Compilation message
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 |
1 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
348 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
344 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |