This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
#define FOR(i,l,r) for(int i=(l); i<=(r); ++i)
#define REP(i,l,r) for(int i=(l); i<(r); ++i)
#define FORD(i,r,l) for(int i=(r); i>=(l); --i)
#define REPD(i,r,l) for(int i=(r)-1; i>=(l); --i)
using namespace std;
const int N = 1e5 + 5;
int M[256];
int pre[N][3][3];
void init(string a, string b) {
M['A'] = 0; M['T'] = 1; M['C'] = 2;
REP(i, 0, a.length()) {
REP(j, 0, 3) REP(w, 0, 3) pre[i + 1][j][w] = pre[i][j][w];
if (a[i] != b[i]) ++pre[i + 1][M[a[i]]][M[b[i]]];
}
}
int choice[3][3];
int num[3];
int get_distance(int x, int y) {
++y;
REP(i, 0, 3) num[i] = 0;
REP(i, 0, 3) REP(j, 0, 3) {
choice[i][j] = pre[y][i][j] - pre[x][i][j];
num[i] += choice[i][j];
num[j] -= choice[i][j];
}
REP(i, 0, 3) if (num[i]) return -1;
int res = 0, m1 = 1e5, m2 = 1e5;
REP(i, 0, 3) REP(j, i + 1, 3) {
int tmp = min(choice[i][j], choice[j][i]);
res += tmp;
m2 = min(m2, max(choice[i][j], choice[j][i]) - tmp);
if (m2 < m1) swap(m1, m2);
}
return res + m1 + m2;
}
Compilation message (stderr)
dna.cpp: In function 'void init(std::string, std::string)':
dna.cpp:3:36: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
3 | #define REP(i,l,r) for(int i=(l); i<(r); ++i)
| ^
dna.cpp:13:5: note: in expansion of macro 'REP'
13 | REP(i, 0, a.length()) {
| ^~~
dna.cpp:15:46: warning: array subscript has type 'char' [-Wchar-subscripts]
15 | if (a[i] != b[i]) ++pre[i + 1][M[a[i]]][M[b[i]]];
| ^
dna.cpp:15:55: warning: array subscript has type 'char' [-Wchar-subscripts]
15 | if (a[i] != b[i]) ++pre[i + 1][M[a[i]]][M[b[i]]];
| ^
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |