제출 #480840

#제출 시각아이디문제언어결과실행 시간메모리
480840PoPularPlusPlusDNA 돌연변이 (IOI21_dna)C++17
100 / 100
50 ms6956 KiB
#include "dna.h" #include <bits/stdc++.h> using namespace std; #define ll long long #define ull unsigned long long #define pb(e) push_back(e) #define sv(a) sort(a.begin(),a.end()) #define sa(a,n) sort(a,a+n) #define mp(a,b) make_pair(a,b) #define vf first #define vs second #define ar array #define all(x) x.begin(),x.end() const int inf = 0x3f3f3f3f; const int mod = 1000000007; const double PI=3.14159265358979323846264338327950288419716939937510582097494459230; bool remender(ll a , ll b){return a%b;} const int N = 100002; int cnt[N][3][3]; void init(std::string a, std::string b) { int n = a.size(); memset(cnt,0,sizeof cnt); for(int i = 0; i < n; i++){ if(i){ for(int j = 0; j < 3; j++){ for(int k = 0; k < 3; k++){ cnt[i][j][k] = cnt[i-1][j][k]; } } } if(a[i] != b[i]){ int x , y; if(a[i] == 'A')x = 0; else if(a[i] == 'T')x = 1; else x = 2; if(b[i] == 'A')y = 0; else if(b[i] == 'T')y = 1; else y = 2; cnt[i][x][y]++; } } } int get_distance(int x, int y) { int a[3][3]; for(int i = 0; i < 3; i++){ for(int j = 0; j < 3; j++){ a[i][j] = cnt[y][i][j]; if(x > 0)a[i][j] -= cnt[x-1][i][j]; } } int ans = 0; int t = min(a[0][1] , a[1][0]); ans += t; a[0][1] -= t; a[1][0] -= t; t = min(a[0][2] , a[2][0]); ans += t; a[0][2] -= t; a[2][0] -= t; t = min(a[1][2] , a[2][1]); ans += t; a[1][2] -= t; a[2][1] -= t; int r0 = a[0][1] + a[0][2] , r1 = a[1][0] + a[1][2] , r2 = a[2][0] + a[2][1]; if(r0 == r1 && r1 == r2){ ans += r0 + r0; } else ans = -1; return ans; } /* int main(){ int n , q; cin >> n >> q; string a , b; cin >> a >> b; init(a,b); while(q--){ int x , y; cin >> x >> y; cout << get_distance(x , y); } } */
#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...