Submission #692230

#TimeUsernameProblemLanguageResultExecution timeMemory
692230thegamercoder19Mutating DNA (IOI21_dna)C++17
0 / 100
194 ms11892 KiB
#include "dna.h"
#define _CRT_SECURE_NO_WARNINGS
#include <bits/stdc++.h>
 
#define M_PI       3.14159265358979323846
#define FILER 0
using ll = long long;
using ull = unsigned long long;
using ld = long double;
const ll MOD = pow(10, 9) + 7;
const ll INFL = 0x3f3f3f3f3f3f3f3f;
const ull INFUL = 0x3f3f3f3f3f3f3f3f;
const ll INFT = 0x3f3f3f3f;
const ull MAX = 1LL << 24;
const ll MODD = 998244353;
const double EPS = 1e-10;
#define V vector
#define pll pair<ll, ll>
#define pull2 pair<ull,ull>
#define MS multiset
#define M map
#define Q queue
#define PQ priority_queue
#define IOF ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define FOR(typ,i,a,b,c) for(typ i = a; i < b; i += c)
#define FORR(typ,i,a,b,c) for(typ i = a; i > b; i -= c)
#define FORA(a,i) for(auto &i : a)
#define all(v) v.begin(),v.end()
#define sz(v) v.size()
#define sorta(a) sort(all(a))
#define sortd(a) sort(all(a), greater<ll>())
#define setp(x) setprecision(x)<<fixed
#define RET return
#define log(a,b) log(b)/log(a)
#define WH(s) while(s)
#define WHI(t) WH(t--)
#define YES cout<<"YES"<<endl;
#define NO cout<<"NO"<<endl;
#define Yes cout<<"Yes"<<endl;
#define No cout<<"No"<<endl;
#define YESNO(s) cout << (s ? "YES" : "NO") << endl;
#define YesNo(s) cout<<(s?"Yes":"No")<<endl;
#define TYP 0
using namespace std;
V<pll> pa, pc, pt;
V<ll> pf;
V<V<ll>> g;
V<bool> used;
ll res,ia,ic,it;
map<char, V<ll>> h;
void dfs(ll u)
{
	used[u] = 1;
	res++;
	FORA(g[u], v) { if (used[v])RET; dfs(v); }
}
void init(std::string a, std::string b) 
{
	ll n = a.size();
	a = '$' + a, b = '$' + b;
	pa.resize(n + 1); pc.resize(n + 1); pt.resize(n + 1); pf.resize(n + 1);
	g.resize(n + 1);
	used.resize(n + 1);
	FOR(ll, i, 1, n + 1, 1)
	{
		if (b[i] != a[i])h[b[i]].push_back(i);
		pa[i] = { pa[i - 1].first + (a[i] == 'A'), pa[i - 1].second + (b[i] == 'A') };
		pc[i] = { pc[i - 1].first + (a[i] == 'C'), pc[i - 1].second + (b[i] == 'C') };
		pt[i] = { pt[i - 1].first + (a[i] == 'T'), pt[i - 1].second + (b[i] == 'T') };
	}
		
	FOR(ll, i, 1, n + 1, 1)
	{
		if (b[i] == a[i])continue;
		if(h[a[i]].size())g[i].push_back(*h[a[i]].begin()), h[a[i]].erase(h[a[i]].begin());
	}
	FOR(ll, i, 1, n + 1, 1)
	{
		if (!used[i]) {
			res = 0; dfs(i);
			pf[i] = max(0LL,res-1);
		}
		pf[i] += pf[i - 1];
	}
}
 
int get_distance(int x, int y) {
	x++, y++;
	if(pa[y].first-pa[x-1].first!=pa[y].second-pa[x-1].second)return -1;
    if(pc[y].first-pc[x-1].first!=pc[y].second-pc[x-1].second)return -1;
    if(pt[y].first-pt[x-1].first!=pt[y].second-pt[x-1].second)return -1;
	return pf[y] - pf[x - 1];
}
#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...