#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
typedef long long int ll;
int main() {
int k, n;
cin >> k >> n;
if (k != 1) return 1;
vector<int> a;
// vector<int> ba;
// vector<int> bb;
ll sum = 0;
for (int i = 0; i < n; i++) {
char sa, sb;
int ia, ib;
cin >> sa >> ia >> sb >> ib;
if (sa == sb) {
sum += abs(ia-ib);
continue;
}
a.push_back(ia);
a.push_back(ib);
sum += 1;
// ba.push_back(ia);
// bb.push_back(ib);
}
sort(a.begin(), a.end());
int p = a[a.size() / 2];
// cout << p << "\n";
for (auto v : a) {
sum += abs(v-p);
}
cout << sum << "\n";
}
# |
결과 |
실행 시간 |
메모리 |
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 |
344 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 |
344 KB |
Output is correct |
8 |
Correct |
1 ms |
344 KB |
Output is correct |
9 |
Correct |
1 ms |
344 KB |
Output is correct |
10 |
Correct |
1 ms |
348 KB |
Output is correct |
11 |
Correct |
1 ms |
344 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
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 |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
1 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
1 ms |
348 KB |
Output is correct |
10 |
Correct |
0 ms |
348 KB |
Output is correct |
11 |
Correct |
1 ms |
348 KB |
Output is correct |
12 |
Correct |
23 ms |
1492 KB |
Output is correct |
13 |
Correct |
56 ms |
1564 KB |
Output is correct |
14 |
Correct |
34 ms |
1488 KB |
Output is correct |
15 |
Correct |
34 ms |
984 KB |
Output is correct |
16 |
Correct |
38 ms |
1568 KB |
Output is correct |
17 |
Correct |
56 ms |
1572 KB |
Output is correct |
18 |
Correct |
53 ms |
1492 KB |
Output is correct |
19 |
Correct |
55 ms |
1344 KB |
Output is correct |
20 |
Correct |
42 ms |
1492 KB |
Output is correct |
21 |
Correct |
49 ms |
1488 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
1 ms |
344 KB |
Execution failed because the return code was nonzero |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
0 ms |
348 KB |
Execution failed because the return code was nonzero |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
0 ms |
344 KB |
Execution failed because the return code was nonzero |
2 |
Halted |
0 ms |
0 KB |
- |