Submission #442132

#TimeUsernameProblemLanguageResultExecution timeMemory
442132SorahISAMutating DNA (IOI21_dna)C++17
35 / 100
52 ms8788 KiB
#include "dna.h" #pragma GCC optimize("Ofast", "unroll-loops") #include <bits/stdc++.h> using namespace std; // #define int long long // #define double long double using pii = pair<int, int>; template<typename T> using Prior = std::priority_queue<T>; template<typename T> using prior = std::priority_queue<T, vector<T>, greater<T>>; #define X first #define Y second #define eb emplace_back #define pb pop_back #define pf pop_front #define ALL(x) begin(x), end(x) #define RALL(x) rbegin(x), rend(x) namespace { mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count()); const int maxn = 1 << 17; int N; string A, B; vector<tuple<int, int, int>> cntA, cntB; vector<array<array<int, 3>, 3>> _trans; int to_int[256]; inline int is_same_dna(int L, int R) { if (L == 0) return cntA[R] == cntB[R]; auto &[LAA, LAT, LAC] = cntA[L-1]; auto &[LBA, LBT, LBC] = cntB[L-1]; auto &[RAA, RAT, RAC] = cntA[R]; auto &[RBA, RBT, RBC] = cntB[R]; return (RAA - LAA == RBA - LBA) and (RAT - LAT == RBT - LBT) and (RAC - LAC == RBC - LBC); } array<array<int, 3>, 3> get_range_trans(int L, int R) { if (L == 0) return _trans[R]; array<array<int, 3>, 3> tmp; for (int i = 0; i < 3; ++i) { for (int j = 0; j < 3; ++j) { tmp[i][j] = _trans[R][i][j] - _trans[L-1][i][j]; } } return tmp; } } /// end of namespace void init(string _A, string _B) { A = _A, B = _B, N = A.size(); cntA.assign(N, {0, 0, 0}), cntB.assign(N, {0, 0, 0}); _trans.resize(N); to_int['A'] = 0, to_int['T'] = 1, to_int['C'] = 2; for (int i = 0; i < N; ++i) { if (i) cntA[i] = cntA[i-1], cntB[i] = cntB[i-1], _trans[i] = _trans[i-1]; auto &[AA, AT, AC] = cntA[i]; auto &[BA, BT, BC] = cntB[i]; if (A[i] == 'A') ++AA; if (A[i] == 'T') ++AT; if (A[i] == 'C') ++AC; if (B[i] == 'A') ++BA; if (B[i] == 'T') ++BT; if (B[i] == 'C') ++BC; ++_trans[i][to_int[A[i]]][to_int[B[i]]]; } } int get_distance(int L, int R) { if (!is_same_dna(L, R)) return -1; auto trans = get_range_trans(L, R); return trans[0][1]; /// 'A' or 'T' }

Compilation message (stderr)

dna.cpp: In function 'void init(std::string, std::string)':
dna.cpp:68:9: warning: this 'if' clause does not guard... [-Wmisleading-indentation]
   68 |         if (A[i] == 'A') ++AA; if (A[i] == 'T') ++AT; if (A[i] == 'C') ++AC;
      |         ^~
dna.cpp:68:32: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'if'
   68 |         if (A[i] == 'A') ++AA; if (A[i] == 'T') ++AT; if (A[i] == 'C') ++AC;
      |                                ^~
dna.cpp:69:9: warning: this 'if' clause does not guard... [-Wmisleading-indentation]
   69 |         if (B[i] == 'A') ++BA; if (B[i] == 'T') ++BT; if (B[i] == 'C') ++BC;
      |         ^~
dna.cpp:69:32: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'if'
   69 |         if (B[i] == 'A') ++BA; if (B[i] == 'T') ++BT; if (B[i] == 'C') ++BC;
      |                                ^~
dna.cpp:70:32: warning: array subscript has type 'char' [-Wchar-subscripts]
   70 |         ++_trans[i][to_int[A[i]]][to_int[B[i]]];
      |                                ^
dna.cpp:70:46: warning: array subscript has type 'char' [-Wchar-subscripts]
   70 |         ++_trans[i][to_int[A[i]]][to_int[B[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...