Submission #738603

#TimeUsernameProblemLanguageResultExecution timeMemory
738603ToxtaqMutating DNA (IOI21_dna)C++17
56 / 100
105 ms26032 KiB
#include<bits/stdc++.h> using namespace std; string a, b; /// 0-A, 1-T, 2-C vector<int>prefA, prefT, prefC; vector<int>pref2A, pref2T, pref2C; vector<vector<vector<int>>>table; map<char, int>mp; void init(string s1, string s2){ a = s1; b = s2; mp['A'] = 0; mp['T'] = 1; mp['C'] = 2; prefA.resize(s1.size() + 1); prefT.resize(s1.size() + 1); prefC.resize(s1.size() + 1); pref2A.resize(s1.size() + 1); pref2T.resize(s1.size() + 1); pref2C.resize(s1.size() + 1); table.assign(s1.size(), vector<vector<int>>(3, vector<int>(3))); for(int i = 0;i < s1.size();++i){ prefA[i + 1] = prefA[i] + (s1[i] == 'A'); prefT[i + 1] = prefT[i] + (s1[i] == 'T'); prefC[i + 1] = prefC[i] + (s1[i] == 'C'); pref2A[i + 1] = pref2A[i] + (s2[i] == 'A'); pref2T[i + 1] = pref2T[i] + (s2[i] == 'T'); pref2C[i + 1] = pref2C[i] + (s2[i] == 'C'); if(i)table[i] = table[i - 1]; table[i][mp[a[i]]][mp[b[i]]]++; } } int get_distance(int x, int y){ int res = 0, cnt = 0; vector<vector<int>>cur(3, vector<int>(3)); if(prefA[y + 1] - prefA[x] != pref2A[y + 1] - pref2A[x])return -1; if(prefT[y + 1] - prefT[x] != pref2T[y + 1] - pref2T[x])return -1; if(prefC[y + 1] - prefC[x] != pref2C[y + 1] - pref2C[x])return -1; for(int i = 0;i < 3;++i){ for(int j = 0;j < 3;++j){ cur[i][j] = table[y][i][j]; if(x - 1 >= 0)cur[i][j] -= table[x - 1][i][j]; } } for(int i = 0;i < 3;++i){ for(int j = 0;j < 3;++j){ if(i == j)continue; int num = min(cur[i][j], cur[j][i]); res += num; cur[i][j] -= num; cur[j][i] -= num; cnt += cur[i][j]; } } if(cnt == 0)return res; return cnt - 1 + res; } //int main() //{ // string a, b; // cin >> a >> b; // init(a, b); // int q; // cin >> q; // while(q--){ // int l, r; // cin >> l >> r; // cout << get_distance(l, r) << '\n'; // } //}

Compilation message (stderr)

dna.cpp: In function 'void init(std::string, std::string)':
dna.cpp:22:21: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   22 |     for(int i = 0;i < s1.size();++i){
      |                   ~~^~~~~~~~~~~
#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...