Submission #1342656

#TimeUsernameProblemLanguageResultExecution timeMemory
1342656limitsMutating DNA (IOI21_dna)C++20
100 / 100
22 ms6124 KiB
#pragma GCC optimize("Ofast")
#pragma GCC optimize("O3,unroll-loops")

#include <bits/stdc++.h>

using namespace std;

#define f0r(i, n) for (auto i = 0; i < (n); ++i)
#define fnr(i, n, k) for (auto i = (n); i < (k); ++i)
#define all(v) (v).begin(), (v).end()
#define pb push_back
#define F first
#define S second
#define ctn(x) cout << x << '\n'
#define forl(a, l) for (auto a : l)
#define ctl(l) for (auto &a : (l)) cout << a << ' '; cout << endl;
#define lb(v, x) (lower_bound(all(v), x) - begin(v))
#define ub(v, x) (upper_bound(all(v), x) - begin(v))
#define pq priority_queue

template <class T>
using V = vector<T>;
using ll = long long;
using vi = V<int>;
using vl = V<ll>;
using pi = pair<int, int>;
using ti = tuple<int, int, int>;
using Adj = V<vi>;
using vvi = V<vi>;

#include "dna.h"

vi pfA, pfT, pfC;

using Mat = array<array<int, 3>, 3>;
V<Mat> pfM;

void init(string a, string b) {
	int n = a.size();
	pfM.assign(n+1, {});
	f0r(i, n) {
		int c1 = a[i] == 'A' ? 0 : (a[i] == 'T' ? 1 : 2);
		int c2 = b[i] == 'A' ? 0 : (b[i] == 'T' ? 1 : 2);
		pfM[i+1] = pfM[i];
		pfM[i+1][c1][c2]++;
	}
}

int get_distance(int x, int y) {
	Mat mtL = pfM[x], mt = pfM[y+1];
	f0r(i, 3) f0r(j, 3) mt[i][j] -= mtL[i][j];
	vi sm(3);
	f0r(i, 3) f0r(j, 3) {
		sm[i] += mt[i][j];
		sm[j] -= mt[i][j];
	}
	if (sm[0] || sm[1] || sm[2]) return -1;
	int ans = 0;
	f0r(i, 3) f0r(j, 3) if (i < j) {
		int a = min(mt[i][j], mt[j][i]);
		mt[i][j] -= a, mt[j][i] -= a;
		ans += a;
	}
	return ans + 2*(mt[0][1] + mt[1][0]);
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...