#include <bits/stdc++.h>
using namespace std;
using ll = long long; using pii = pair<ll,ll>;
int main() {
ios_base::sync_with_stdio(false); cin.tie(0);
ll K,N; cin >> K >> N;
vector<pii> v;
ll ans = 0;
for (ll i=0;i<N;i++) {
string p,q; ll s,t;
cin >> p >> s >> q >> t;
if (p==q) {
ans += abs(s-t);
} else {
ans++;
v.push_back({min(s,t),max(s,t)});
}
}
if (K==1) {
vector<ll> v2;
for (pii p0: v) {
v2.push_back(p0.first);
v2.push_back(p0.second);
}
sort(v2.begin(),v2.end());
for (ll x: v2) {
ans += abs(x-v2[v2.size()/2]);
}
cout << ans; exit(0);
}
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
604 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 |
344 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
0 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 |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
600 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
1 ms |
600 KB |
Output is correct |
4 |
Correct |
1 ms |
348 KB |
Output is correct |
5 |
Correct |
1 ms |
464 KB |
Output is correct |
6 |
Correct |
1 ms |
356 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
1 ms |
344 KB |
Output is correct |
9 |
Correct |
0 ms |
348 KB |
Output is correct |
10 |
Correct |
0 ms |
348 KB |
Output is correct |
11 |
Correct |
0 ms |
348 KB |
Output is correct |
12 |
Correct |
20 ms |
5892 KB |
Output is correct |
13 |
Correct |
32 ms |
7368 KB |
Output is correct |
14 |
Correct |
23 ms |
6096 KB |
Output is correct |
15 |
Correct |
18 ms |
4076 KB |
Output is correct |
16 |
Correct |
23 ms |
6612 KB |
Output is correct |
17 |
Correct |
31 ms |
7232 KB |
Output is correct |
18 |
Correct |
25 ms |
6868 KB |
Output is correct |
19 |
Correct |
32 ms |
7332 KB |
Output is correct |
20 |
Correct |
22 ms |
7120 KB |
Output is correct |
21 |
Correct |
27 ms |
7116 KB |
Output is correct |
# |
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 |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
0 ms |
344 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |