Submission #872604

#TimeUsernameProblemLanguageResultExecution timeMemory
872604LucaLucaMMutating DNA (IOI21_dna)C++17
71 / 100
1574 ms3924 KiB
#include "dna.h" #include <iostream> #include <algorithm> std::string s, q; int n; void init(std::string a, std::string b) { n = (int) a.size(); for (auto &ch : a) { if (ch == 'A') { ch = 0; } else if (ch == 'C') { ch = 1; } else { ch = 2; } } for (auto &ch : b) { if (ch == 'A') { ch = 0; } else if (ch == 'C') { ch = 1; } else { ch = 2; } } s = '$' + a, q = '$' + b; } int get_distance(int x, int y) { ++x, ++y; int bad = 0; int cnt[3][3] = {}; int delta[3] = {}; for (int i = x; i <= y; i++) { cnt[s[i]][q[i]]++; delta[s[i]]++; delta[q[i]]--; } if (delta[0] != 0 || delta[1] != 0 || delta[2] != 0) { return -1; } std::vector<int> p = {0, 1, 2}; int answer = 0; do { int cur = 0; for (int i = 0; i < 3; i++) { for (int j = i + 1; j < 3; j++) { cur += cnt[p[i]][p[j]]; } } answer = std::max(answer, cur); } while (std::next_permutation(p.begin(), p.end())); return answer; } /** 6 3 ATACAT ACTATA 1 3 4 5 3 5 123 231 **/

Compilation message (stderr)

dna.cpp: In function 'int get_distance(int, int)':
dna.cpp:37:13: warning: array subscript has type 'char' [-Wchar-subscripts]
   37 |     cnt[s[i]][q[i]]++;
      |             ^
dna.cpp:37:19: warning: array subscript has type 'char' [-Wchar-subscripts]
   37 |     cnt[s[i]][q[i]]++;
      |                   ^
dna.cpp:38:15: warning: array subscript has type 'char' [-Wchar-subscripts]
   38 |     delta[s[i]]++;
      |               ^
dna.cpp:39:15: warning: array subscript has type 'char' [-Wchar-subscripts]
   39 |     delta[q[i]]--;
      |               ^
dna.cpp:33:7: warning: unused variable 'bad' [-Wunused-variable]
   33 |   int bad = 0;
      |       ^~~
#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...