#include <bits/stdc++.h>
using namespace std;
#define ff first
#define ss second
#define pb push_back
#define ll long long
#define pii pair <int, int>
#define sz size()
const int N = 2e5 + 5;
vector <ll> v;
char s[N], f[N];
ll a[N], b[N];
int k, n;
int main() {
// freopen ("input.txt", "r", stdin);
ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
cin >> k >> n;
for (int i = 1; i <= n; ++i) {
cin >> s[i] >> a[i] >> f[i] >> b[i];
if (s[i] != f[i]) {
v.pb (a[i]);
v.pb (b[i]);
}
}
sort (v.begin(), v.end());
ll idx = 0;
if (!v.empty()) idx = v[(int)v.sz / 2];
ll sum = 0;
for (int i = 1; i <= n; ++i) {
if (s[i] == f[i]) {
sum += abs (a[i] - b[i]);
}
else {
sum += abs (idx - a[i]);
sum += abs (idx - b[i]);
sum++;
}
}
cout << sum;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
2392 KB |
Output is correct |
2 |
Correct |
1 ms |
2396 KB |
Output is correct |
3 |
Correct |
0 ms |
2396 KB |
Output is correct |
4 |
Correct |
1 ms |
2396 KB |
Output is correct |
5 |
Correct |
1 ms |
2396 KB |
Output is correct |
6 |
Correct |
1 ms |
2392 KB |
Output is correct |
7 |
Correct |
1 ms |
2396 KB |
Output is correct |
8 |
Correct |
1 ms |
2396 KB |
Output is correct |
9 |
Correct |
1 ms |
2396 KB |
Output is correct |
10 |
Correct |
1 ms |
2396 KB |
Output is correct |
11 |
Correct |
1 ms |
2396 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
2392 KB |
Output is correct |
2 |
Correct |
1 ms |
2392 KB |
Output is correct |
3 |
Correct |
1 ms |
2396 KB |
Output is correct |
4 |
Correct |
1 ms |
2392 KB |
Output is correct |
5 |
Correct |
1 ms |
2396 KB |
Output is correct |
6 |
Correct |
0 ms |
2396 KB |
Output is correct |
7 |
Correct |
1 ms |
2396 KB |
Output is correct |
8 |
Correct |
0 ms |
2396 KB |
Output is correct |
9 |
Correct |
1 ms |
2396 KB |
Output is correct |
10 |
Correct |
1 ms |
2392 KB |
Output is correct |
11 |
Correct |
1 ms |
2396 KB |
Output is correct |
12 |
Correct |
14 ms |
4824 KB |
Output is correct |
13 |
Correct |
28 ms |
4824 KB |
Output is correct |
14 |
Correct |
25 ms |
4824 KB |
Output is correct |
15 |
Correct |
16 ms |
3800 KB |
Output is correct |
16 |
Correct |
16 ms |
4956 KB |
Output is correct |
17 |
Correct |
19 ms |
4820 KB |
Output is correct |
18 |
Correct |
23 ms |
5000 KB |
Output is correct |
19 |
Correct |
27 ms |
5024 KB |
Output is correct |
20 |
Correct |
18 ms |
4824 KB |
Output is correct |
21 |
Correct |
24 ms |
4824 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
2396 KB |
Output is correct |
2 |
Correct |
0 ms |
2396 KB |
Output is correct |
3 |
Incorrect |
0 ms |
2396 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
2396 KB |
Output is correct |
2 |
Correct |
0 ms |
2396 KB |
Output is correct |
3 |
Incorrect |
1 ms |
2396 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
2396 KB |
Output is correct |
2 |
Correct |
0 ms |
2396 KB |
Output is correct |
3 |
Incorrect |
0 ms |
2396 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |