Submission #1057435

#TimeUsernameProblemLanguageResultExecution timeMemory
1057435TrentMutating DNA (IOI21_dna)C++17
0 / 100
1599 ms3672 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; string a, b; void init(std::string a, std::string b) { ::a = a; ::b = b; forR(i, a.size()) REP(j, i, a.size()) { get_distance(i, j); } } int id(char v) { return v == 'A' ? 0 : v == 'C' ? 1 : 2; } int get_distance(int x, int y) { vector<vi> cnt(3, vi(3, 0)); REP(i, x, y+1) { cnt[id(a[i])][id(b[i])]++; } 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]; if(y - x <= 2) { int real = -1; string as=::a.substr(x, y-x+1), bs=::b.substr(x, y-x+1); if(as == bs) real = 0; forR(i, as.size()) forR(j, as.size()) { swap(as[i], as[j]); if(as == bs) real = real == -1 ? 1 : min(real, 1); forR(k, as.size()) forR(l, as.size()) { swap(as[k], as[l]); if(as == bs) real = real == -1 ? 2 : min(real, 2); swap(as[k], as[l]); } swap(as[i], as[j]); } if(ret != real) { cerr << x << ' ' << y << ' ' << ret << ' ' << real << '\n'; throw; } } 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:14:2: note: in expansion of macro 'forR'
   14 |  forR(i, a.size()) REP(j, 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:14:20: note: in expansion of macro 'REP'
   14 |  forR(i, a.size()) REP(j, i, a.size()) {
      |                    ^~~
dna.cpp: In function 'int get_distance(int, int)':
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:39:3: note: in expansion of macro 'forR'
   39 |   forR(i, as.size()) forR(j, as.size()) {
      |   ^~~~
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:39:22: note: in expansion of macro 'forR'
   39 |   forR(i, as.size()) forR(j, as.size()) {
      |                      ^~~~
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:42:4: note: in expansion of macro 'forR'
   42 |    forR(k, as.size()) forR(l, as.size()) {
      |    ^~~~
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:42:23: note: in expansion of macro 'forR'
   42 |    forR(k, as.size()) forR(l, as.size()) {
      |                       ^~~~
#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...