제출 #526273

#제출 시각아이디문제언어결과실행 시간메모리
526273pokmui9909DNA 돌연변이 (IOI21_dna)C++17
100 / 100
79 ms30408 KiB
#include <bits/stdc++.h> #include "dna.h" using namespace std; using ll = long long; string A, B; ll C1[100005][5], C2[100005][5]; ll S[100005][5][5]; ll f(char v){ if(v == 'A') return 1; if(v == 'T') return 2; if(v == 'C') return 3; } void init(std::string a, std::string b){ A = a, B = b; A = ' ' + A, B = ' ' + B; for(int i = 1; i <= A.size(); i++){ for(int j = 1; j <= 3; j++){ C1[i][j] = C1[i - 1][j]; } C1[i][f(A[i])]++; } for(int i = 1; i <= B.size(); i++){ for(int j = 1; j <= 3; j++){ C2[i][j] = C2[i - 1][j]; } C2[i][f(B[i])]++; } for(int i = 1; i <= A.size(); i++){ for(int j = 1; j <= 3; j++){ for(int k = 1; k <= 3; k++){ S[i][j][k] = S[i - 1][j][k]; } } S[i][f(A[i])][f(B[i])]++; } } bool Check(ll L, ll R){ for(int i = 1; i <= 3; i++){ if(C1[R][i] - C1[L - 1][i] != C2[R][i] - C2[L - 1][i]){ return 0; } } return 1; } int get_distance(int x, int y){ x++, y++; if(!Check(x, y)) return -1; vector<vector<ll>> T(5, vector<ll>(5)); for(int i = 1; i <= 3; i++){ for(int j = 1; j <= 3; j++){ T[i][j] = S[y][i][j] - S[x - 1][i][j]; } } ll ans = 0; for(int i = 1; i <= 3; i++){ ll p = i, q = (i == 3 ? 1 : p + 1); ll K = min(T[p][q], T[q][p]); ans += K; T[p][q] -= K; T[q][p] -= K; } ans += max(T[1][2], T[2][1]) * 2; return ans; }

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

dna.cpp: In function 'void init(std::string, std::string)':
dna.cpp:17:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   17 |     for(int i = 1; i <= A.size(); i++){
      |                    ~~^~~~~~~~~~~
dna.cpp:23:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   23 |     for(int i = 1; i <= B.size(); i++){
      |                    ~~^~~~~~~~~~~
dna.cpp:29:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   29 |     for(int i = 1; i <= A.size(); i++){
      |                    ~~^~~~~~~~~~~
dna.cpp: In function 'll f(char)':
dna.cpp:13:1: warning: control reaches end of non-void function [-Wreturn-type]
   13 | }
      | ^
#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...