Submission #497369

#TimeUsernameProblemLanguageResultExecution timeMemory
497369Maqsut_03Mutating DNA (IOI21_dna)C++17
43 / 100
1588 ms5744 KiB
#include<bits/stdc++.h> #include "dna.h" using namespace std; string a, b, a1, b1; int n; map <char, int> arr, mp; void init(string a0, string b0) { a = a0; b = b0; a1 = a; b1 = b; n = a.length(); } int get_distance(int x, int y) { int ans = 0; a = a1; b = b1; arr.clear(); mp.clear(); for (int i = x; i <= y; i++) arr[a[i]]++, arr[b[i]]--, mp[a[i]]++, mp[b[i]]++; for (char i = 'A'; i <= 'Z'; i++) if (arr[i] != 0) return -1; string a2, b2; for (int i=x;i<=y;i++) a2=a2+a[i], b2=b2+b[i]; a=a2; b=b2; if (mp['A']+mp['T'] == 2*(y-x+1)){ for (int i=0;i<=y-x;i++){ if (a[i] != b[i]) ans++; } // cout << 1; return ans/2+(ans % 2); } for (int i=0;i<=y-x;i++){ bool ok=0; for (int j=i+1;j<=y-x;j++){ if (a[i] == b[j] and b[i] != a[i] and a[j] == b[i]){ ok=1; ans++; swap(b[i], b[j]); // cout << 1; } } if (!ok){ for (int j=i+1;j<=y-x;j++){ if (a[i] == b[j] and b[i] != a[i]){ ans++; swap(b[i], b[j]); // cout << b <<" "; } } } } return ans; }
#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...