#include <bits/stdc++.h>
#define all(v) v.begin(), v.end()
using namespace std;
typedef long long ll;
int k, n;
vector<ll> v, x, y;
ll ans;
int main(){
ios_base::sync_with_stdio(false); cin.tie(nullptr);
cin >> k >> n;
if(k == 2) return -1;
v.reserve(n+n);
for(int i=1; i<=n; i++){
char a, c; int b, d;
cin >> a >> b >> c >> d;
if(a == c){ ans += llabs(b - d); continue; }
ans++; v.push_back(b); v.push_back(d);
x.push_back(b);
y.push_back(d);
}
n = x.size(); sort(all(v));
ll t = v[n-1];
for(int i=0; i<n; i++){
ans += llabs(t - x[i]);
ans += llabs(t - y[i]);
}
cout << ans;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
384 KB |
Output is correct |
2 |
Correct |
5 ms |
384 KB |
Output is correct |
3 |
Correct |
5 ms |
384 KB |
Output is correct |
4 |
Correct |
5 ms |
384 KB |
Output is correct |
5 |
Correct |
5 ms |
384 KB |
Output is correct |
6 |
Correct |
5 ms |
384 KB |
Output is correct |
7 |
Correct |
5 ms |
512 KB |
Output is correct |
8 |
Correct |
5 ms |
384 KB |
Output is correct |
9 |
Correct |
5 ms |
384 KB |
Output is correct |
10 |
Correct |
5 ms |
384 KB |
Output is correct |
11 |
Correct |
5 ms |
384 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
4 ms |
384 KB |
Output is correct |
2 |
Correct |
5 ms |
384 KB |
Output is correct |
3 |
Correct |
5 ms |
384 KB |
Output is correct |
4 |
Correct |
5 ms |
384 KB |
Output is correct |
5 |
Correct |
5 ms |
384 KB |
Output is correct |
6 |
Correct |
5 ms |
384 KB |
Output is correct |
7 |
Correct |
5 ms |
384 KB |
Output is correct |
8 |
Correct |
5 ms |
384 KB |
Output is correct |
9 |
Correct |
5 ms |
384 KB |
Output is correct |
10 |
Correct |
5 ms |
384 KB |
Output is correct |
11 |
Correct |
5 ms |
384 KB |
Output is correct |
12 |
Correct |
29 ms |
4580 KB |
Output is correct |
13 |
Correct |
58 ms |
6116 KB |
Output is correct |
14 |
Correct |
40 ms |
4588 KB |
Output is correct |
15 |
Correct |
35 ms |
3828 KB |
Output is correct |
16 |
Correct |
38 ms |
5480 KB |
Output is correct |
17 |
Correct |
44 ms |
5988 KB |
Output is correct |
18 |
Correct |
48 ms |
5604 KB |
Output is correct |
19 |
Correct |
56 ms |
5988 KB |
Output is correct |
20 |
Correct |
39 ms |
5604 KB |
Output is correct |
21 |
Correct |
48 ms |
5860 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
5 ms |
384 KB |
Execution failed because the return code was nonzero |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
4 ms |
384 KB |
Execution failed because the return code was nonzero |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
5 ms |
384 KB |
Execution failed because the return code was nonzero |
2 |
Halted |
0 ms |
0 KB |
- |