Submission #437187

#TimeUsernameProblemLanguageResultExecution timeMemory
437187jlallas384Mutating DNA (IOI21_dna)C++17
100 / 100
420 ms119236 KiB
#include <bits/stdc++.h> #include "dna.h" using namespace std; vector<vector<map<char,int>>> pre1; vector<map<string,int>> pre2; const vector<pair<string,string>> a = {{"AT","TA"},{"CT","TC"},{"CA","AC"}}; void init(string a, string b){ pre1.assign(a.size() + 1,vector<map<char,int>>(2)); pre2.resize(a.size() + 1); for(int i = 0; i < a.size(); i++){ pre1[i + 1] = pre1[i]; pre1[i + 1][0][a[i]]++; pre1[i + 1][1][b[i]]++; pre2[i + 1] = pre2[i]; pre2[i + 1][string() + a[i] + b[i]]++; } } int get_distance(int x, int y){ if(pre1[y + 1][0]['A'] - pre1[x][0]['A'] != pre1[y + 1][1]['A'] - pre1[x][1]['A']) return -1; if(pre1[y + 1][0]['T'] - pre1[x][0]['T'] != pre1[y + 1][1]['T'] - pre1[x][1]['T']) return -1; int ans = 0, dif = 0; for(auto [s1,s2]: a){ int r1 = pre2[y + 1][s1] - pre2[x][s1]; int r2 = pre2[y + 1][s2] - pre2[x][s2]; dif += r1 + r2 - min(r1,r2) * 2; ans += min(r1,r2); } assert(dif % 3 == 0); return ans + dif / 3 * 2; }

Compilation message (stderr)

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