#include <bits/stdc++.h>
using namespace std;
#define int long long
#define sz(x) (int)x.size()
#define ff first
#define ss second
const int N = 300005;
const int M = 1e9 + 7;
int T, n, k, s1[N], s2[N];
char c1[N], c2[N];
signed main(){
ios::sync_with_stdio(false); cin.tie(0);
cin >> k >> n;
for(int i = 1; i <= n; i++){
cin >> c1[i] >> s1[i] >> c2[i] >> s2[i];
}
if(k == 1){
int ans = 0;
vector <int> v;
for(int i = 1; i <= n; i++){
if(c1[i] == c2[i]){
ans += abs(s1[i]-s2[i]);
}
else {
v.push_back(s1[i]);
v.push_back(s2[i]);
}
}
sort(v.begin(), v.end());
int x = 0;
if(sz(v) > 0) x = (v.front()+v.back()+1) / 2;
for(auto i : v){
ans += abs(i-x);
}
cout << ans+sz(v)/2 << "\n";
return 0;
}
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
4440 KB |
Output is correct |
2 |
Correct |
1 ms |
4440 KB |
Output is correct |
3 |
Correct |
1 ms |
4444 KB |
Output is correct |
4 |
Incorrect |
1 ms |
4572 KB |
Output isn't correct |
5 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
4444 KB |
Output is correct |
2 |
Correct |
0 ms |
4444 KB |
Output is correct |
3 |
Correct |
1 ms |
4444 KB |
Output is correct |
4 |
Incorrect |
1 ms |
4444 KB |
Output isn't correct |
5 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1 ms |
4444 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1 ms |
4444 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1 ms |
4440 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |