You are creating a vaccine to fight against a worldwide novel pandemic virus. A vaccine contains a weakened virus that is injected inside people to produce antibodies to let it fight against the virus. The study of interaction among RNA of various viruses is quite necessary for this. An RNA consists of four types of molecules Guanine (), Adenine (), Cytosine (), and Uracil ().
You are given the structures of RNA for the pandemic virus and several vaccine viruses in the form of strings containing characters , , , and representing respective molecules. You know that if there is higher interaction between the pandemic virus and vaccine virus, the better the vaccine will be. You also know that the only interaction between any two RNAs is a result of the interaction between their Guanine () and Cytosine () molecules. Formally, if the strings for RNA structures are and , then you must consider the following points:
- One molecule of Guanine () of and one molecule of Cytosine () of will lead to one unit of interaction.
- One molecule of Guanine () of and one molecule of Cytosine () of will lead to one unit of interaction.
- Any other pair of molecules do not add to any interactions.
In this way, the total interaction between and is calculated as the sum of individual molecule pair interactions (as discussed above).
You must find the best available vaccine.
Example:
Input: n=2, m=5, s="ACGGU", value={6,8}, vaccines={"AGCAAA","UAUAAGAG"}
Output: 1
Approach
C++
#include <bits/stdc++.h>using namespace std;int findVaccines(int n, int m, string s,vector<string> &str, vector<int> &x){long long max1 = 0;long long ans = 0, c = 0, g = 0;for (long long i = 0; i < m; i++){if (s[i] == 'C')c++;else if (s[i] == 'G')g++;}for (long long i = 0; i < n; i++){long long cnt = 0;for (long long j = 0; j < x[i]; j++){if (str[i][j] == 'C')cnt += g;else if (str[i][j] == 'G')cnt += c;}if (cnt > max1){ans = i + 1;max1 = cnt;}}return ans;}int main(){long long n = 2, m = 5;string s = "ACGGU";vector<int> value = {6, 8};vector<string> vaccines = {"AGCAAA", "UAUAAGAG"};cout << findVaccines(n, m, s, vaccines, value);return 0;}
No comments:
Post a Comment