#include <bits/stdc++.h>
using namespace std;
#define nyahalo ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define otsumiko exit(0);
#define mikodanye priority_queue<pair<long long, long long>, vector<pair<long long, long long> >, greater<pair<long long, long long> > >
#define mikochi priority_queue<long long, vector<long long>, greater<long long> >
long long k, n, s[100069], t[100069], ca, cb, ad = 0, ans = 0, sz, md, fp, sp, cs, mn;
char p[100069], q[100069];
vector<long long> vc;
int main() {
nyahalo
long long i, j, ii;
cin >> k >> n;
if (k == 1) {
for (i=1; i<=n; i++) {
cin >> p[i] >> s[i] >> q[i] >> t[i];
ca = p[i]-'A';
cb = q[i]-'A';
if (ca == cb) {
ad += abs(s[i]-t[i]);
} else {
vc.push_back(s[i]);
vc.push_back(t[i]);
}
}
sort(vc.begin(), vc.end());
sz = vc.size();
md = sz/2;
for (i=0; i<sz; i++) {
ans += abs(vc[i]-vc[md]);
}
ans += sz/2;
ans += ad;
cout << ans << "\n";
otsumiko
//uwu
}
if (n<=100) {
for (i=1; i<=n; i++) {
cin >> p[i] >> s[i] >> q[i] >> t[i];
ca = p[i]-'A';
cb = q[i]-'A';
if (ca == cb) {
ad += abs(s[i]-t[i]);
} else {
vc.push_back(s[i]);
vc.push_back(t[i]);
}
}
sort(vc.begin(), vc.end());
sz = vc.size();
ans = 1e17;
if (sz == 0) {
ans = 0;
}
for (i=0; i<sz; i++) {
for (j=i+1; j<sz; j++) {
fp = vc[i];
sp = vc[j];
cs = 0;
for (ii=1; ii<=n; ii++) {
if (p[ii] == q[ii]) {
continue;
}
mn = min(abs(fp-s[ii])+abs(fp-t[ii])+1, abs(sp-s[ii])+abs(sp-t[ii])+1);
cs += mn;
}
ans = min(ans, cs);
}
}
ans += ad;
cout << ans << "\n";
otsumiko
}
cout << "sek\n";
otsumiko
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Correct |
0 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 |
340 KB |
Output is correct |
6 |
Correct |
1 ms |
340 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 |
0 ms |
212 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 |
340 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 |
25 ms |
3788 KB |
Output is correct |
13 |
Correct |
38 ms |
3664 KB |
Output is correct |
14 |
Correct |
28 ms |
3664 KB |
Output is correct |
15 |
Correct |
22 ms |
2408 KB |
Output is correct |
16 |
Correct |
28 ms |
3792 KB |
Output is correct |
17 |
Correct |
27 ms |
3788 KB |
Output is correct |
18 |
Correct |
33 ms |
3736 KB |
Output is correct |
19 |
Correct |
41 ms |
3720 KB |
Output is correct |
20 |
Correct |
29 ms |
3740 KB |
Output is correct |
21 |
Correct |
36 ms |
3692 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
328 KB |
Output is correct |
3 |
Correct |
5 ms |
340 KB |
Output is correct |
4 |
Correct |
5 ms |
340 KB |
Output is correct |
5 |
Correct |
2 ms |
340 KB |
Output is correct |
6 |
Correct |
0 ms |
340 KB |
Output is correct |
7 |
Correct |
9 ms |
344 KB |
Output is correct |
8 |
Correct |
8 ms |
340 KB |
Output is correct |
9 |
Correct |
8 ms |
324 KB |
Output is correct |
10 |
Correct |
8 ms |
340 KB |
Output is correct |
11 |
Correct |
11 ms |
340 KB |
Output is correct |
12 |
Correct |
9 ms |
340 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
340 KB |
Output is correct |
3 |
Correct |
8 ms |
348 KB |
Output is correct |
4 |
Correct |
5 ms |
340 KB |
Output is correct |
5 |
Correct |
1 ms |
340 KB |
Output is correct |
6 |
Correct |
0 ms |
340 KB |
Output is correct |
7 |
Correct |
9 ms |
344 KB |
Output is correct |
8 |
Correct |
8 ms |
340 KB |
Output is correct |
9 |
Correct |
8 ms |
340 KB |
Output is correct |
10 |
Correct |
9 ms |
340 KB |
Output is correct |
11 |
Correct |
7 ms |
340 KB |
Output is correct |
12 |
Correct |
8 ms |
296 KB |
Output is correct |
13 |
Incorrect |
0 ms |
212 KB |
Output isn't correct |
14 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
324 KB |
Output is correct |
3 |
Correct |
5 ms |
340 KB |
Output is correct |
4 |
Correct |
6 ms |
340 KB |
Output is correct |
5 |
Correct |
2 ms |
340 KB |
Output is correct |
6 |
Correct |
1 ms |
328 KB |
Output is correct |
7 |
Correct |
9 ms |
340 KB |
Output is correct |
8 |
Correct |
8 ms |
352 KB |
Output is correct |
9 |
Correct |
8 ms |
340 KB |
Output is correct |
10 |
Correct |
8 ms |
328 KB |
Output is correct |
11 |
Correct |
9 ms |
340 KB |
Output is correct |
12 |
Correct |
8 ms |
340 KB |
Output is correct |
13 |
Incorrect |
1 ms |
340 KB |
Output isn't correct |
14 |
Halted |
0 ms |
0 KB |
- |