# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1057439 | Trent | Mutating DNA (IOI21_dna) | C++17 | 44 ms | 7776 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include "dna.h"
#include "bits/stdc++.h"
using namespace std;
#define forR(i, x) for(int i = 0; i < (x); ++i)
#define REP(i, a, b) for(int i = (a); i < (b); ++i)
typedef long long ll;
typedef vector<int> vi;
const int MN = 1e5 + 10;
string a, b;
int psa[MN][3][3];
int id(char v) {
return v == 'A' ? 0 : v == 'C' ? 1 : 2;
}
void init(std::string a, std::string b) {
::a = a;
::b = b;
forR(i, a.size()) {
psa[i][id(a[i])][id(b[i])]++;
}
REP(i, 1, a.size()) forR(j, 3) forR(k, 3) psa[i][j][k] += psa[i-1][j][k];
}
int get_distance(int x, int y) {
vector<vi> cnt(3, vi(3, 0));
forR(i, 3) forR(j, 3) cnt[i][j] = psa[y][i][j] - (x == 0 ? 0 : psa[x-1][i][j]);
int ab=min(cnt[0][1], cnt[1][0]), ac=min(cnt[0][2], cnt[2][0]), bc=min(cnt[1][2], cnt[2][1]);
cnt[0][1]-=ab, cnt[1][0]-=ab;
cnt[0][2]-=ac, cnt[2][0]-=ac;
cnt[1][2]-=bc, cnt[2][1]-=bc;
int ret = -1;
if(cnt[0][1] == cnt[2][0] && cnt[2][0] == cnt[1][2] && cnt[1][0] + cnt[2][1] + cnt[0][2] == 0) ret = ab + ac + bc + 2 * cnt[0][1];
else if(cnt[1][0] == cnt[2][1] && cnt[2][1] == cnt[0][2] && cnt[0][1] + cnt[2][0] + cnt[1][2] == 0) ret = ab + ac + bc + 2 * cnt[1][0];
return ret;
}
Compilation message (stderr)
# | 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... |