#include <bits/stdc++.h>
#define ll long long
#define X first
#define Y second
#define MP make_pair
using namespace std;
const int N = 1e5 + 12;
const ll INF = 1e15;
int n, k;
vector< pair<int, int> > gr;
int main () {
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
cin >> k >> n;
ll res = 0;
for(int i = 1;i <= n;i++){
char x1, x2;
int y1, y2;
cin >> x1 >> y1 >> x2 >> y2;
if(y1 > y2)
swap(y1, y2);
if(x1 != x2){
gr.push_back(MP(y1, -1));
gr.push_back(MP(y2, 1));
res += 1;
}
else{
res += y2 - y1;
}
}
sort(gr.begin(), gr.end());
int mxcnt = 0, curs = 0;
for(pair<int, int> v: gr){
curs -= v.Y;
mxcnt = max(mxcnt, curs);
}
int my_edge = 0;
for(pair<int, int> v: gr){
curs -= v.Y;
if(curs == mxcnt){
my_edge = v.X;
}
}
//cerr << my_edge << "\n";
for(pair<int, int> v: gr){
res += abs(my_edge - v.X);
}
cout << res;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
384 KB |
Output is correct |
2 |
Correct |
0 ms |
384 KB |
Output is correct |
3 |
Correct |
1 ms |
384 KB |
Output is correct |
4 |
Incorrect |
2 ms |
384 KB |
Output isn't correct |
5 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
384 KB |
Output is correct |
2 |
Correct |
1 ms |
384 KB |
Output is correct |
3 |
Correct |
1 ms |
384 KB |
Output is correct |
4 |
Incorrect |
1 ms |
384 KB |
Output isn't correct |
5 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
384 KB |
Output is correct |
2 |
Correct |
0 ms |
384 KB |
Output is correct |
3 |
Incorrect |
0 ms |
384 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
384 KB |
Output is correct |
2 |
Correct |
1 ms |
384 KB |
Output is correct |
3 |
Incorrect |
0 ms |
384 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
384 KB |
Output is correct |
2 |
Correct |
1 ms |
384 KB |
Output is correct |
3 |
Incorrect |
1 ms |
384 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |