#include<bits/stdc++.h>
#define ll long long
#define pb push_back
using namespace std;
const int maxN = 1e5+1;
int k, n;
struct Tbridge
{
char a, b;
ll x, y;
bool chk;
}p[maxN];
ll ans = 0;
void Input()
{
vector<ll> v;
cin >> k >> n;
for(int i = 1; i <= n; i++)
{
cin >> p[i].a >> p[i].x >> p[i].b >> p[i].y;
if(p[i].a == p[i].b)
{
ans += abs(p[i].y - p[i].x);
p[i].chk = false;
}
else
{
v.pb(p[i].x);
v.pb(p[i].y);
p[i].chk = true;
}
}
sort(v.begin(), v.end());
if(k == 1)
{
if(v.empty())
{
cout << ans;
return;
}
ll res = (int)v.size() / 2;
ll h = v[res];
for(int i = 1; i <= n; i++)
if(p[i].chk)
ans += abs(h - p[i].x) + abs(h - p[i].y) + 1;
cout << ans;
return;
}
/* int res = v.size()/3;
int h = v[res], h2 = v[res*2];
for(int i = 1; i <= n; i++)
if(p[i].chk)
ans += min(abs(h - p[i].x) + abs(h - p[i].y) + 1, abs(h2 - p[i].x) + abs(h2 - p[i].y) + 1);
cout << ans;*/
}
int main()
{
ios_base::sync_with_stdio(0);
cin.tie(0);
Input();
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
232 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
340 KB |
Output is correct |
4 |
Correct |
1 ms |
340 KB |
Output is correct |
5 |
Correct |
1 ms |
340 KB |
Output is correct |
6 |
Correct |
1 ms |
388 KB |
Output is correct |
7 |
Correct |
1 ms |
340 KB |
Output is correct |
8 |
Correct |
1 ms |
340 KB |
Output is correct |
9 |
Correct |
1 ms |
340 KB |
Output is correct |
10 |
Correct |
1 ms |
340 KB |
Output is correct |
11 |
Correct |
1 ms |
340 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
340 KB |
Output is correct |
3 |
Correct |
1 ms |
340 KB |
Output is correct |
4 |
Correct |
1 ms |
340 KB |
Output is correct |
5 |
Correct |
1 ms |
328 KB |
Output is correct |
6 |
Correct |
2 ms |
344 KB |
Output is correct |
7 |
Correct |
1 ms |
340 KB |
Output is correct |
8 |
Correct |
1 ms |
340 KB |
Output is correct |
9 |
Correct |
1 ms |
340 KB |
Output is correct |
10 |
Correct |
1 ms |
340 KB |
Output is correct |
11 |
Correct |
1 ms |
340 KB |
Output is correct |
12 |
Correct |
34 ms |
5388 KB |
Output is correct |
13 |
Correct |
44 ms |
5348 KB |
Output is correct |
14 |
Correct |
29 ms |
4856 KB |
Output is correct |
15 |
Correct |
24 ms |
3284 KB |
Output is correct |
16 |
Correct |
30 ms |
5392 KB |
Output is correct |
17 |
Correct |
32 ms |
5456 KB |
Output is correct |
18 |
Correct |
51 ms |
5464 KB |
Output is correct |
19 |
Correct |
54 ms |
5392 KB |
Output is correct |
20 |
Correct |
35 ms |
5428 KB |
Output is correct |
21 |
Correct |
35 ms |
5380 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
212 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
284 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
212 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |