Submission #985443

#TimeUsernameProblemLanguageResultExecution timeMemory
985443Zbyszek99Mutating DNA (IOI21_dna)C++17
Compilation error
0 ms0 KiB
#include "dna.h" #include <bits/stdc++.h> #define rep(i,n) for(int i = 0; i < n; i++) using namespace std; map<string, int> typ = {{"AT",0},{"AC",1},{"TA",2},{"TC",3},{"CA",4},{"CT",5},{"AA",6},{"TT",7},{"CC",8}}; map<char, int> znak = {{'A',0},{'T',1},{'C',2}}; int pref_typ[100001][9]; int pref_znak[100001][2][3]; int n; void init(string s1, string s2) { n = (int)s.size(); rep(i,n) { rep(j,3) { if(znak[s1[i]] == j) pref_znak[i+1][0][znak[s1[i]]] = pref_znak[i][0][znak[s1[i]]] +1; else pref_znak[i+1][0][znak[s1[i]]] = pref_znak[i][0][znak[s1[i]]]; } } rep(i,n) { rep(j,3) { if(znak[s1[i]] == j) pref_znak[i+1][0][znak[s2[i]]] = pref_znak[i][0][znak[s2[i]]] +1; else pref_znak[i+1][0][znak[s2[i]]] = pref_znak[i][0][znak[s2[i]]]; } } rep(i,n) { rep(z1,3) { rep(z2,3) { string s; s += s1[i]; s+= s2[i]; if(znak[s1[i]] == z1 && znak[s2[i]] == z2) pref_typ[i+1][s] = pref_typ[i][s] +1; else pref_typ[i+1][s] = pref_typ[i][s]; } } } } int get_distance(int p, int k) { int T1 = pref_znak[k+1][0][znak['T']] - pref_znak[p][0][znak['T']]; int C1 = pref_znak[k+1][0][znak['C']] - pref_znak[p][0][znak['C']]; int A1 = pref_znak[k+1][0][znak['A']] - pref_znak[p][0][znak['A']]; int T2 = pref_znak[k+1][1][znak['T']] - pref_znak[p][1][znak['T']]; int C2 = pref_znak[k+1][1][znak['C']] - pref_znak[p][1][znak['C']]; int A2 = pref_znak[k+1][1][znak['A']] - pref_znak[p][1][znak['A']]; if(T1 != T2 || C1 != C2 || A1 != A2) { return -1; } int ust = k-p+1; int ans = 0; ust -= pref_typ[k+1][typ["AA"]] - pref_typ[p][typ["AA"]]; ust -= pref_typ[k+1][typ["TT"]] - pref_typ[p][typ["TT"]]; ust -= pref_typ[k+1][typ["CC"]] - pref_typ[p][typ["CC"]]; ust -= min(pref_typ[k+1][typ["TA"]] - pref_typ[p][typ["TA"]],pref_typ[k+1][typ["AT"]] - pref_typ[p][typ["AT"]])*2; ans += min(pref_typ[k+1][typ["TA"]] - pref_typ[p][typ["TA"]],pref_typ[k+1][typ["AT"]] - pref_typ[p][typ["AT"]]); ust -= min(pref_typ[k+1][typ["TC"]] - pref_typ[p][typ["TC"]],pref_typ[k+1][typ["CT"]] - pref_typ[p][typ["CT"]])*2; ans += min(pref_typ[k+1][typ["TC"]] - pref_typ[p][typ["TC"]],pref_typ[k+1][typ["CT"]] - pref_typ[p][typ["CT"]]); ust -= min(pref_typ[k+1][typ["CA"]] - pref_typ[p][typ["CA"]],pref_typ[k+1][typ["AC"]] - pref_typ[p][typ["AC"]])*2; ans += min(pref_typ[k+1][typ["CA"]] - pref_typ[p][typ["CA"]],pref_typ[k+1][typ["AC"]] - pref_typ[p][typ["AC"]]); return ans+ust-1; }

Compilation message (stderr)

dna.cpp: In function 'void init(std::string, std::string)':
dna.cpp:14:14: error: 's' was not declared in this scope; did you mean 's1'?
   14 |     n = (int)s.size();
      |              ^
      |              s1
dna.cpp:38:73: error: no match for 'operator[]' (operand types are 'int [9]' and 'std::string' {aka 'std::__cxx11::basic_string<char>'})
   38 |                 if(znak[s1[i]] == z1 && znak[s2[i]] == z2) pref_typ[i+1][s] = pref_typ[i][s] +1;
      |                                                                         ^
dna.cpp:38:90: error: no match for 'operator[]' (operand types are 'int [9]' and 'std::string' {aka 'std::__cxx11::basic_string<char>'})
   38 |                 if(znak[s1[i]] == z1 && znak[s2[i]] == z2) pref_typ[i+1][s] = pref_typ[i][s] +1;
      |                                                                                          ^
dna.cpp:39:35: error: no match for 'operator[]' (operand types are 'int [9]' and 'std::string' {aka 'std::__cxx11::basic_string<char>'})
   39 |                 else pref_typ[i+1][s] = pref_typ[i][s];
      |                                   ^
dna.cpp:39:52: error: no match for 'operator[]' (operand types are 'int [9]' and 'std::string' {aka 'std::__cxx11::basic_string<char>'})
   39 |                 else pref_typ[i+1][s] = pref_typ[i][s];
      |                                                    ^