Submission #957149

#TimeUsernameProblemLanguageResultExecution timeMemory
957149DeltaStructMutating DNA (IOI21_dna)C++17
100 / 100
126 ms6472 KiB
#include "dna.h" #include <bits/stdc++.h> using namespace std; string x,y,u="ACT"; int n; map<string,vector<int>> acc; void init(string a,string b){ x = a,y = b,n = a.size(); for (auto c:u) for (auto d:u) if (c!=d){ string i = {c,d}; acc[i] = {0}; for (int k(0);k < n;++k) acc[i].emplace_back(acc[i].back()+(x[k]==c&&y[k]==d)); } } int get_distance(int l,int r){ ++r; auto sb = [&acc,&l,&r](string s,string t){return (acc[s][r]-acc[s][l])-(acc[t][r]-acc[t][l]); }; if (sb("AC","CA")!=sb("CT","TC")||sb("AC","CA")!=sb("TA","AT")) return -1; int res = abs(sb("AC","CA"))*2; for (int i(0);i < 3;++i) for (int k(i+1);k < 3;++k){ string s = {u[i],u[k]},t = {u[k],u[i]}; res += min(acc[s][r]-acc[s][l],acc[t][r]-acc[t][l]); } return res; }

Compilation message (stderr)

dna.cpp: In function 'int get_distance(int, int)':
dna.cpp:16:15: warning: capture of variable 'acc' with non-automatic storage duration
   16 |   auto sb = [&acc,&l,&r](string s,string t){return (acc[s][r]-acc[s][l])-(acc[t][r]-acc[t][l]); };
      |               ^~~
dna.cpp:5:52: note: 'std::map<std::__cxx11::basic_string<char>, std::vector<int> > acc' declared here
    5 | string x,y,u="ACT"; int n; map<string,vector<int>> acc;
      |                                                    ^~~
#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...