Submission #600385

#TimeUsernameProblemLanguageResultExecution timeMemory
600385OrazBMutating DNA (IOI21_dna)C++17
100 / 100
189 ms6200 KiB
#include <bits/stdc++.h> #include "dna.h" #define N 100005 #define wr cout << "Continue debugging\n"; #define ll long long int #define pii pair <string, int> #define pb push_back #define ff first #define ss second using namespace std; int ans, pr[7][N], m[7]; vector <string> v = {"AT", "TA", "AC", "CA", "CT", "TC"}; int find(string a){ for (int i = 0; i < v.size(); i++) if (v[i] == a) return i; } void calc(){ int mn = min(m[0], m[1]); ans += mn; m[0] -= mn; m[1] -= mn; mn = min(m[2], m[3]); ans += mn; m[2] -= mn; m[3] -= mn; mn = min(m[4], m[5]); ans += mn; m[4] -= mn; m[5] -= mn; } void init(string a, string b){ int n = a.size(); a = ' ' + a; b = ' ' + b; for (int i = 1; i <= n; i++){ if (a[i] != b[i]){ if (a[i] == 'A' and b[i] == 'T') pr[0][i]++; else if (a[i] == 'T' and b[i] == 'A') pr[1][i]++; else if (a[i] == 'A' and b[i] == 'C') pr[2][i]++; else if (a[i] == 'C' and b[i] == 'A') pr[3][i]++; else if (a[i] == 'C' and b[i] == 'T') pr[4][i]++; else pr[5][i]++; } } for (int i = 2; i <= n; i++){ for (int x = 0; x < 6; x++) pr[x][i] += pr[x][i - 1]; } } int get_distance(int l, int r){ l++; r++; ans = 0; for (int i = 0; i < 6; i++) m[i] = pr[i][r] - pr[i][l - 1]; calc(); for (auto s : v){ string c = "", t1 = ""; c += s[1]; if ('A' != s[0] and 'A' != s[1]) c += 'A'; else if ('T' != s[0] and 'T' != s[1]) c += 'T'; else c += 'C'; t1 += s[0]; t1 += c[1]; int idx1 = find(s); int idx2 = find(c); int idx3 = find(t1); int mn = min(m[idx1], m[idx2]); ans += mn; m[idx1] -= mn; m[idx2] -= mn; m[idx3] += mn; } calc(); for (int i = 0; i < 6; i++) if (m[i]) return -1; return ans; } // int main () // { // ios::sync_with_stdio(false); // cin.tie(0); // int n1, q1; // string a, b; // cin >> n1 >> q1 >> a >> b; // init(a, b); // while(q1--){ // int x, y; // cin >> x >> y; // cout << get_distance(x, y); // } // }

Compilation message (stderr)

dna.cpp: In function 'int find(std::string)':
dna.cpp:16:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::__cxx11::basic_string<char> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   16 |  for (int i = 0; i < v.size(); i++) if (v[i] == a) return i;
      |                  ~~^~~~~~~~~~
dna.cpp:17:1: warning: control reaches end of non-void function [-Wreturn-type]
   17 | }
      | ^
#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...