제출 #712613

#제출 시각아이디문제언어결과실행 시간메모리
712613danikoynovDNA 돌연변이 (IOI21_dna)C++17
100 / 100
833 ms8780 KiB
#include "dna.h" #include <bits/stdc++.h> using namespace std; const int maxn = 1e5 + 10; string s, t; int pref[2][3][maxn]; int kf[3][3][maxn]; map < char, int > rev; void init(std::string a, std::string b) { s = a; t = b; rev['A'] = 0; rev['C'] = 1; rev['T'] = 2; for (int i = 0; i < a.size(); i ++) { if (i != 0) { for (int p = 0; p < 3; p ++) for (int k = 0; k < 2; k ++) pref[k][p][i] = pref[k][p][i - 1]; for (int p1 = 0; p1 < 3; p1 ++) for (int p2 = 0; p2 < 3; p2 ++) kf[p1][p2][i] = kf[p1][p2][i - 1]; } if (a[i] != b[i]) kf[rev[a[i]]][rev[b[i]]][i] ++; pref[0][rev[a[i]]][i] ++; pref[1][rev[b[i]]][i] ++; } } int get_distance(int x, int y) { string s1 = s.substr(x, y - x + 1); string t1 = t.substr(x, y - x + 1); int df[2][3], pf[3][3]; for (int p = 0; p < 3; p ++) { df[0][p] = pref[0][p][y]; df[1][p] = pref[1][p][y]; } for (int p1 = 0; p1 < 3; p1 ++) for (int p2 = 0; p2 < 3; p2 ++) pf[p1][p2] = kf[p1][p2][y]; if (x != 0) { for (int p = 0; p < 3; p ++) { df[0][p] -= pref[0][p][x - 1]; df[1][p] -= pref[1][p][x - 1]; } for (int p1 = 0; p1 < 3; p1 ++) for (int p2 = 0; p2 < 3; p2 ++) pf[p1][p2] -= kf[p1][p2][x - 1]; } for (int p = 0; p < 3; p ++) if (df[0][p] != df[1][p]) return -1; int ans = 0; for (int p1 = 0; p1 < 3; p1 ++) for (int p2 = 0; p2 < 3; p2 ++) { int mx = min(pf[p1][p2], pf[p2][p1]); ans += mx; pf[p1][p2] -= mx; pf[p2][p1] -= mx; } int add = 0; for (int p1 = 0; p1 < 3; p1 ++) for (int p2 = 0; p2 < 3; p2 ++) add += pf[p1][p2]; ans = ans + (add / 3) * 2; return ans; /**for (int i = 0; i < t1.size(); i ++) { if (s1[i] == t1[i]) continue; bool done = false; for (int j = i; j < t1.size(); j ++) { if (s1[j] == t1[i] && t1[j] == s1[i]) { swap(s1[j], s1[i]); ans ++; done = true; break; } } if (!done) { for (int j = i; j < t1.size(); j ++) { if (s1[j] == t1[i] && s1[j] != t1[j]) { swap(s1[j], s1[i]); ans ++; done = true; break; } } } ///cout << i << " : " << j << endl; } return ans;*/ }

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

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