#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define is insert
#define ll long long
#define V vector
#define MS multiset
#define PL pair<ll, ll>
#define F first
#define S second
#define PQ priority_queue
#define f0r(i, begin, finish) for (ll i = begin; i < finish; i ++)
#define For(i, finish, begin) for (ll i = finish; i > begin; i --)
#define all(x) x.begin(), x.end()
#define INF 1000000000000000000
#define inf 1000000000
#define MOD 1000000007
#define len(x) (ll)x.size()
#define fileread(file) ifstream fin; fin.open((string)file + ".in"); ofstream fout; fout.open((string)file + ".out")
#define fastio ios_base::sync_with_stdio(0); cin.tie(nullptr)
template<typename T> istream& operator>>(istream& in, V<T>& a) {for(auto &x : a) in >> x; return in;};
template<typename T> ostream& operator<<(ostream& out, V<T>& a) {for(auto &x : a) out << x << ' '; return out;};
int main () {
int K, N; cin >> K >> N;
ll tot = 0;
if (K == 1) {
V<ll> crits;
V<PL> r;
f0r (i, 0, N) {
char a, b;
ll x, y;
cin >> a >> x >> b >> y;
if (a == b) { tot += abs(x - y); }
else {
crits.pb(x);
crits.pb(y);
tot ++;
r.pb({min(x, y), max(x, y)});
}
}
if (len(crits) > 0) {
sort(all(crits));
ll opt = crits[len(crits) / 2];
for (auto ra : r) {
tot += abs(ra.F - opt) + abs(ra.S - opt);
}
}
cout << tot << endl;
} else {
cout << 22 << endl;
}
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
304 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 |
2 ms |
340 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
300 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 |
308 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 |
2 ms |
312 KB |
Output is correct |
12 |
Correct |
40 ms |
4328 KB |
Output is correct |
13 |
Correct |
79 ms |
5920 KB |
Output is correct |
14 |
Correct |
64 ms |
4724 KB |
Output is correct |
15 |
Correct |
47 ms |
3732 KB |
Output is correct |
16 |
Correct |
56 ms |
5188 KB |
Output is correct |
17 |
Correct |
69 ms |
5932 KB |
Output is correct |
18 |
Correct |
69 ms |
5492 KB |
Output is correct |
19 |
Correct |
87 ms |
5936 KB |
Output is correct |
20 |
Correct |
61 ms |
5564 KB |
Output is correct |
21 |
Correct |
88 ms |
5596 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
0 ms |
212 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
0 ms |
212 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
0 ms |
212 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |