이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
#define rep(i, a, b) for(int i = a; i < (b); ++i)
#define all(x) begin(x), end(x)
#define sz(x) (int)(x).size()
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef vector<int> vi;
template<class T, class U> istream& operator>>(istream &is, pair<T, U>& p) { is >> p.first >> p.second; return is; }
template<class T> istream& operator>>(istream& is, vector<T>& vec) { for(auto &x : vec) cin >> x; return is; }
template<class T, class U> ostream& operator<<(ostream &os, pair<T, U>& p) { os << "<" << p.first << "," << p.second << ">"; return os; }
template<class T> ostream& operator<<(ostream& os, vector<T>& vec) { for(auto x : vec) os << x << " "; return os; }
int conv(char c) {
if (c == 'A') return 0;
else if (c == 'C') return 1;
return 2;
}
const int TYPES = 9, MAXN = 100010;
int prefs[TYPES][MAXN];
int n;
void init(string sa, string sb) {
n = sa.size();
vector<int> a(n), b(n);
for (int i = 0; i < n; i++) {
a[i] = conv(sa[i]);
b[i] = conv(sb[i]);
}
for (int i = 0; i < n; i++) {
int type = a[i] * 3 + b[i];
prefs[type][i]++;
if (i > 0) {
for (int t = 0; t < TYPES; t++) {
prefs[t][i] += prefs[t][i-1];
}
}
}
}
int get_sum(int type, int l, int r) {
if (l == 0) return prefs[type][r];
return prefs[type][r] - prefs[type][l-1];
}
int get_distance(int l, int r) {
vector<int> type_sums(TYPES);
for (int t = 0; t < TYPES; t++) {
type_sums[t] = get_sum(t, l, r);
}
int swaps = 0;
// cancel out on diagonal.
swaps += min(type_sums[1], type_sums[3]);
swaps += min(type_sums[2], type_sums[6]);
swaps += min(type_sums[5], type_sums[7]);
vector<int> rems = {
abs(type_sums[1] - type_sums[3]),
abs(type_sums[2] - type_sums[6]),
abs(type_sums[5] - type_sums[7])
};
if (rems[0] == rems[1] && rems[1] == rems[2]) {
swaps += rems[0] * 2;
return swaps;
}
else return -1;
}
# | 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... |