Submission #464938

#TimeUsernameProblemLanguageResultExecution timeMemory
464938markoMutating DNA (IOI21_dna)C++17
Compilation error
0 ms0 KiB
#include <bits/stdc++.h> using namespace std; vector<unordered_map<char, unordered_map<char, int>>> counts {}; vector<unordered_map<char, int>> absolute_counts {}; void init(const string& a, const string& b) { const int n = a.size(); counts.resize(n + 1); for (int i = 0; i < n; i++) { counts[i + 1] = counts[i]; counts[i + 1][a[i]][b[i]]++; } } int get_distance(int x, int y) { y++; int ans {}; auto cnts = counts[y]; int doubles {}; for (auto a : { 'A', 'C', 'T' }) for (auto b : { 'A', 'C', 'T' }) cnts[a][b] -= counts[x][a][b]; unordered_map<char, int> counts_a {}, counts_b {}; for (auto a : { 'A', 'C', 'T' }) { for (auto b : { 'A', 'C', 'T' }) { counts_a[a] += cnts[a][b]; counts_b[b] += cnts[a][b]; } } for (auto a : { 'A', 'C', 'T' }) { if (counts_a[a] != counts_b[a]) return -1; } for (auto a : { 'A', 'C', 'T' }) { for (auto b : { 'A', 'C', 'T' }) { if (b == a) continue; int take = min(cnts[a][b], cnts[b][a]); doubles += take; } } int triples {}; for (auto a : { 'A', 'C', 'T' }) { for (auto b : { 'A', 'C', 'T' }) { if (b == a) continue; for (auto c : { 'A', 'C', 'T' }) { if (c == b || c == a) continue; auto cnts_ab = cnts[a][b]; auto cnts_bc = cnts[b][c]; auto cnts_ca = cnts[c][a]; int take = min({ cnts[a][b], cnts[b][c], cnts[c][a] }); triples += take; } } } return (triples * 2) / 3 + doubles / 2; } // auto main() -> int // { // init("ATACAT", "ACTATA"); // cout << get_distance(1, 3) << endl; // cout << get_distance(4, 5) << endl; // cout << get_distance(3, 5) << endl; // }

Compilation message (stderr)

dna.cpp: In function 'int get_distance(int, int)':
dna.cpp:64:22: warning: unused variable 'cnts_ab' [-Wunused-variable]
   64 |                 auto cnts_ab = cnts[a][b];
      |                      ^~~~~~~
dna.cpp:65:22: warning: unused variable 'cnts_bc' [-Wunused-variable]
   65 |                 auto cnts_bc = cnts[b][c];
      |                      ^~~~~~~
dna.cpp:66:22: warning: unused variable 'cnts_ca' [-Wunused-variable]
   66 |                 auto cnts_ca = cnts[c][a];
      |                      ^~~~~~~
dna.cpp:23:9: warning: unused variable 'ans' [-Wunused-variable]
   23 |     int ans {};
      |         ^~~
/usr/bin/ld: /tmp/cc8FyMAP.o: in function `main':
grader.cpp:(.text.startup+0x366): undefined reference to `init(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >)'
collect2: error: ld returned 1 exit status