#include <iostream>
#include <bits/stdc++.h>
#define ll long long
using namespace std;
const ll maxn = 2*1e5+5, INF = 4e18+9;
void solve(){
ll k, n;
cin >> k >> n;
vector<ll> a(1);
ll ans = 0;
for(int i = 1; i <= n; i++){
char s1, s2;
int l, r;
cin >> s1 >> l >> s2 >> r;
if(l > r) swap(l, r);
if(s1 == s2){
ans += r-l;
}else{
a.push_back(l);
a.push_back(r);
}
}
sort(a.begin()+1, a.end());
n = a.size()-1;
ans += n/2;
if(k == 1){
int m = (n+1)/2;
for(int i = 1; i <= n; i++){
ans += abs(a[m]-a[i]);
}
cout << ans;
return;
}
}
int main(){
ios_base::sync_with_stdio(false);
cin.tie(NULL);
solve();
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
336 KB |
Output is correct |
2 |
Correct |
1 ms |
336 KB |
Output is correct |
3 |
Correct |
1 ms |
504 KB |
Output is correct |
4 |
Correct |
1 ms |
336 KB |
Output is correct |
5 |
Correct |
1 ms |
336 KB |
Output is correct |
6 |
Correct |
1 ms |
336 KB |
Output is correct |
7 |
Correct |
1 ms |
336 KB |
Output is correct |
8 |
Correct |
1 ms |
336 KB |
Output is correct |
9 |
Correct |
1 ms |
336 KB |
Output is correct |
10 |
Correct |
1 ms |
336 KB |
Output is correct |
11 |
Correct |
1 ms |
504 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
336 KB |
Output is correct |
2 |
Correct |
1 ms |
336 KB |
Output is correct |
3 |
Correct |
1 ms |
336 KB |
Output is correct |
4 |
Correct |
1 ms |
504 KB |
Output is correct |
5 |
Correct |
1 ms |
336 KB |
Output is correct |
6 |
Correct |
1 ms |
336 KB |
Output is correct |
7 |
Correct |
1 ms |
336 KB |
Output is correct |
8 |
Correct |
1 ms |
336 KB |
Output is correct |
9 |
Correct |
1 ms |
336 KB |
Output is correct |
10 |
Correct |
1 ms |
336 KB |
Output is correct |
11 |
Correct |
1 ms |
336 KB |
Output is correct |
12 |
Correct |
16 ms |
4300 KB |
Output is correct |
13 |
Correct |
34 ms |
5324 KB |
Output is correct |
14 |
Correct |
24 ms |
4768 KB |
Output is correct |
15 |
Correct |
19 ms |
2764 KB |
Output is correct |
16 |
Correct |
20 ms |
4812 KB |
Output is correct |
17 |
Correct |
24 ms |
5324 KB |
Output is correct |
18 |
Correct |
26 ms |
5068 KB |
Output is correct |
19 |
Correct |
32 ms |
5324 KB |
Output is correct |
20 |
Correct |
23 ms |
4952 KB |
Output is correct |
21 |
Correct |
31 ms |
5236 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
336 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
336 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
336 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |