이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
#define fr first
#define sc second
#define pii pair<int, int>
#define pb push_back
#define szof(s) (int)s.size()
#define all(s) s.begin(), s.end()
#define fastInp ios_base::sync_with_stdio(0); cin.tie(0);
#define int long long
using namespace std;
const int MAXN = (int)2e5 + 5;
const int INF = 1e18;
pair <char, int> st[MAXN];
pair <char, int> fn[MAXN];
bool ok(int pos) {
return (st[pos].first == fn[pos].first);
}
signed main() {
fastInp;
int n, k;
cin >> k >> n;
for (int i = 1; i <= n; i++) {
cin >> st[i].fr >> st[i].sc >> fn[i].fr >> fn[i].sc;
}
if (k == 1) {
int side = 0;
int bridge = 0;
vector <int> x;
for (int i = 1; i <= n; i++) {
if (ok(i)) {
side += abs(st[i].sc - fn[i].sc);
} else {
x.pb(st[i].sc);
x.pb(fn[i].sc);
}
}
sort(all(x));
int opt = x[szof(x) / 2 - 1];
for (int el : x) {
bridge += abs(opt - el);
}
cout << side + szof(x) / 2 + bridge << endl;
}
else if (k == 2) {
}
}
/*
1 5
B 0 A 4
B 1 B 3
A 5 B 7
B 2 A 6
B 1 A 7
*/
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |