#include <bits/stdc++.h>
#define forr(i, a, b) for (int i = (a); i <= (b); i++)
#define ford(i, a, b) for (int i = (a); i >= (b); i--)
#define forf(i, a, b) for (int i = (a); i < (b); i++)
#define fi first
#define se second
#define pb push_back
#define all(v) v.begin(), v.end()
#define ll long long
#define ld long double
#define pii pair<int, int>
#define pll pair<ll, ll>
#define vi vector<int>
#define vii vector<pii>
#define mask(i) (1LL << (i))
#define bit(x, i) (((x) >> (i)) & 1)
#define bp __builtin_popcountll
#define file "test"
using namespace std;
const int base = 31;
const ll mod = 1e9 + 7;
const ll oo = 1e18;
const int N = 1e6 + 5;
const int M = 1e6;
ll s[N], cnt[N];
int main()
{
ios_base::sync_with_stdio(0);
cin.tie(0);
int K, n;
cin >> K >> n;
ll res = 0;
vector<int> xx;
forr(i, 1, n){
char b1, b2;
int x1, x2;
cin >> b1 >> x1 >> b2 >> x2;
if (b1 == b2){
res += abs(x1 - x2);
}
else {
res++;
xx.pb(x1);
xx.pb(x2);
}
}
sort(all(xx));
ll cost1 = 0;
if (xx.size() >= 1) {
ll med = xx[(xx.size() - 1) >> 1];
forr(i, 0, xx.size() - 1) cost1 += abs(med - xx[i]);
}
cout << res + cost1;
return 0;
}
Compilation message
bridge.cpp: In function 'int main()':
bridge.cpp:2:43: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
2 | #define forr(i, a, b) for (int i = (a); i <= (b); i++)
| ^
bridge.cpp:57:9: note: in expansion of macro 'forr'
57 | forr(i, 0, xx.size() - 1) cost1 += abs(med - xx[i]);
| ^~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
1 ms |
348 KB |
Output is correct |
5 |
Correct |
1 ms |
348 KB |
Output is correct |
6 |
Correct |
1 ms |
348 KB |
Output is correct |
7 |
Correct |
1 ms |
504 KB |
Output is correct |
8 |
Correct |
1 ms |
348 KB |
Output is correct |
9 |
Correct |
0 ms |
348 KB |
Output is correct |
10 |
Correct |
0 ms |
348 KB |
Output is correct |
11 |
Correct |
1 ms |
500 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
1 ms |
348 KB |
Output is correct |
5 |
Correct |
1 ms |
348 KB |
Output is correct |
6 |
Correct |
1 ms |
476 KB |
Output is correct |
7 |
Correct |
1 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
0 ms |
348 KB |
Output is correct |
10 |
Correct |
1 ms |
348 KB |
Output is correct |
11 |
Correct |
0 ms |
348 KB |
Output is correct |
12 |
Correct |
15 ms |
2268 KB |
Output is correct |
13 |
Correct |
29 ms |
3540 KB |
Output is correct |
14 |
Correct |
21 ms |
2780 KB |
Output is correct |
15 |
Correct |
19 ms |
2264 KB |
Output is correct |
16 |
Correct |
19 ms |
3032 KB |
Output is correct |
17 |
Correct |
19 ms |
3532 KB |
Output is correct |
18 |
Correct |
23 ms |
3288 KB |
Output is correct |
19 |
Correct |
28 ms |
3536 KB |
Output is correct |
20 |
Correct |
20 ms |
3224 KB |
Output is correct |
21 |
Correct |
25 ms |
3288 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |