Submission #1057439

#TimeUsernameProblemLanguageResultExecution timeMemory
1057439TrentMutating DNA (IOI21_dna)C++17
100 / 100
44 ms7776 KiB
#include "dna.h" #include "bits/stdc++.h" using namespace std; #define forR(i, x) for(int i = 0; i < (x); ++i) #define REP(i, a, b) for(int i = (a); i < (b); ++i) typedef long long ll; typedef vector<int> vi; const int MN = 1e5 + 10; string a, b; int psa[MN][3][3]; int id(char v) { return v == 'A' ? 0 : v == 'C' ? 1 : 2; } void init(std::string a, std::string b) { ::a = a; ::b = b; forR(i, a.size()) { psa[i][id(a[i])][id(b[i])]++; } REP(i, 1, a.size()) forR(j, 3) forR(k, 3) psa[i][j][k] += psa[i-1][j][k]; } int get_distance(int x, int y) { vector<vi> cnt(3, vi(3, 0)); forR(i, 3) forR(j, 3) cnt[i][j] = psa[y][i][j] - (x == 0 ? 0 : psa[x-1][i][j]); int ab=min(cnt[0][1], cnt[1][0]), ac=min(cnt[0][2], cnt[2][0]), bc=min(cnt[1][2], cnt[2][1]); cnt[0][1]-=ab, cnt[1][0]-=ab; cnt[0][2]-=ac, cnt[2][0]-=ac; cnt[1][2]-=bc, cnt[2][1]-=bc; int ret = -1; if(cnt[0][1] == cnt[2][0] && cnt[2][0] == cnt[1][2] && cnt[1][0] + cnt[2][1] + cnt[0][2] == 0) ret = ab + ac + bc + 2 * cnt[0][1]; else if(cnt[1][0] == cnt[2][1] && cnt[2][1] == cnt[0][2] && cnt[0][1] + cnt[2][0] + cnt[1][2] == 0) ret = ab + ac + bc + 2 * cnt[1][0]; return ret; }

Compilation message (stderr)

dna.cpp: In function 'void init(std::string, std::string)':
dna.cpp:4:37: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
    4 | #define forR(i, x) for(int i = 0; i < (x); ++i)
      |                                     ^
dna.cpp:19:2: note: in expansion of macro 'forR'
   19 |  forR(i, a.size()) {
      |  ^~~~
dna.cpp:5:41: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
    5 | #define REP(i, a, b) for(int i = (a); i < (b); ++i)
      |                                         ^
dna.cpp:22:2: note: in expansion of macro 'REP'
   22 |  REP(i, 1, a.size()) forR(j, 3) forR(k, 3) psa[i][j][k] += psa[i-1][j][k];
      |  ^~~
#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...