Submission #1052847

#TimeUsernameProblemLanguageResultExecution timeMemory
1052847amongus_pvpMutating DNA (IOI21_dna)C++17
0 / 100
22 ms6360 KiB
#include <iostream> #include <vector> #include <string> using namespace std; const int ALPHABET_SIZE = 3; vector<vector<int>> prefixSumA; vector<vector<int>> prefixSumB; void init(string a, string b) { int n = a.size(); // Initialize prefix sum arrays prefixSumA.assign(ALPHABET_SIZE, vector<int>(n + 1, 0)); prefixSumB.assign(ALPHABET_SIZE, vector<int>(n + 1, 0)); // Mapping from character to index: A -> 0, T -> 1, C -> 2 auto charToIndex = [](char c) -> int { if (c == 'A') return 0; if (c == 'T') return 1; return 2; // 'C' }; for (int i = 0; i < n; ++i) { for (int j = 0; j < ALPHABET_SIZE; ++j) { prefixSumA[j][i + 1] = prefixSumA[j][i]; prefixSumB[j][i + 1] = prefixSumB[j][i]; } prefixSumA[charToIndex(a[i])][i + 1]++; prefixSumB[charToIndex(b[i])][i + 1]++; } } int get_distance(int x, int y) { vector<int> freqA(ALPHABET_SIZE), freqB(ALPHABET_SIZE); for (int i = 0; i < ALPHABET_SIZE; ++i) { freqA[i] = prefixSumA[i][y + 1] - prefixSumA[i][x]; freqB[i] = prefixSumB[i][y + 1] - prefixSumB[i][x]; } if (freqA != freqB) return -1; // Calculate the number of mutations required string subA = "", subB = ""; for (int i = x; i <= y; ++i) { subA += freqA[0]-- > 0 ? 'A' : (freqA[1]-- > 0 ? 'T' : 'C'); subB += freqB[0]-- > 0 ? 'A' : (freqB[1]-- > 0 ? 'T' : 'C'); } int swaps = 0; for (int i = 0; i < subA.size(); ++i) { if (subA[i] != subB[i]) { swaps++; } } return swaps / 2; }

Compilation message (stderr)

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