제출 #719177

#제출 시각아이디문제언어결과실행 시간메모리
719177thimote75DNA 돌연변이 (IOI21_dna)C++17
100 / 100
75 ms16620 KiB
#include "dna.h" #include <bits/stdc++.h> using namespace std; int to_int(char ch) { if (ch == 'A') return 0; if (ch == 'C') return 1; if (ch == 'T') return 2; assert(false); } struct SGD { int m[3][3]; void init () { for (int i = 0; i < 3; i ++) for (int j = 0; j < 3; j ++) m[i][j] = 0; } SGD () { init(); } SGD (char a, char b) { init(); int ia = to_int(a); int ib = to_int(b); m[ia][ib] ++; } SGD merge (SGD &other) { SGD res; for (int i = 0; i < 3; i ++) for (int j = 0; j < 3; j ++) res.m[i][j] = m[i][j] + other.m[i][j]; return res; } int flux (int i) { int f = 0; for (int j = 0; j < 3; j ++) { if (j == i) continue ; f -= m[i][j]; f += m[j][i]; } return f; } int distance () { if (flux(0) != 0 || flux(1) != 0 || flux(2) != 0) return -1; int r[3][3]; for (int i = 0; i < 3; i ++) for (int j = 0; j < 3; j ++) r[i][j] = m[i][j]; int dist = 0; for (int i = 0; i < 3; i ++) { for (int j = i + 1; j < 3; j ++) { dist += min(r[j][i], r[i][j]); r[i][j] -= r[j][i]; r[j][i] = 0; } } int residual = abs(r[0][2]); if (residual != abs(r[0][1])) return -1; if (residual != abs(r[1][2])) return -1; dist += 2 * residual; return dist; } }; struct SegTree { int size, start, height; vector<SGD> tree; SegTree () = default; SegTree (vector<SGD> &values) { size = values.size(); height = ceil(log2(size)); start = 1 << height; tree.resize(start << 1); for (int i = 0; i < size; i ++) tree[i + start] = values[i]; for (int i = start - 1; i >= 1; i --) { int n0 = i << 1; int n1 = n0 + 1; tree[i] = tree[n0].merge(tree[n1]); } } SGD query (int x, int y) { x += start; y += start; SGD res; while (x < y) { if ((x & 1) == 1) res = res.merge(tree[x]); if ((y & 1) == 0) res = res.merge(tree[y]); x = (x + 1) >> 1; y = (y - 1) >> 1; } if (x == y) res = res.merge(tree[x]); return res; } }; vector<SGD> object_array; SegTree tree; void init(string a, string b) { object_array.resize(a.size()); for (int i = 0; i < a.size(); i ++) object_array[i] = SGD(a[i], b[i]); tree = SegTree(object_array); } int get_distance(int x, int y) { SGD res = tree.query(x, y); return res.distance(); }

컴파일 시 표준 에러 (stderr) 메시지

dna.cpp: In function 'void init(std::string, std::string)':
dna.cpp:129:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  129 |  for (int i = 0; i < a.size(); 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...