제출 #638438

#제출 시각아이디문제언어결과실행 시간메모리
638438abcisosm5DNA 돌연변이 (IOI21_dna)C++17
100 / 100
96 ms23528 KiB
#include <bits/stdc++.h> using namespace std; vector<vector<vector<int>>> v; int ctoi(char c){ if(c == 'A') return 0; else if(c == 'T') return 1; return 2; } void init(string a, string b){ //O(N) v = vector<vector<vector<int>>>(a.length()); v[0] = vector<vector<int>>(3, vector<int>(3)); v[0][ctoi(a[0])][ctoi(b[0])] = 1; for(int i = 1; i < a.length(); i++){ v[i] = v[i-1]; v[i][ctoi(a[i])][ctoi(b[i])]++; } } int get_distance(int x, int y){ //O(1) //check if possible vector<vector<int>> dif = v[y]; if(x > 0){ for(int i = 0; i < 3; i++){ for(int j = 0; j < 3; j++){ dif[i][j] -= v[x-1][i][j]; } } } for(int i = 0; i < 3; i++){ int coli, rowi; coli = rowi = 0; for(int j = 0; j < 3; j++){ coli += dif[i][j]; rowi += dif[j][i]; } if(coli != rowi) return -1; } //calculate total # swaps needed int mins[3] = {min(dif[0][1], dif[1][0]), min(dif[0][2], dif[2][0]), min(dif[1][2], dif[2][1])}; int maxs[3] = {max(dif[0][1], dif[1][0]), max(dif[0][2], dif[2][0]), max(dif[1][2], dif[2][1])}; int oneswap = mins[0] + mins[1] + mins[2]; int twoswap = (maxs[0]-mins[0]+maxs[1]-mins[1]+maxs[2]-mins[2])*2/3; return oneswap + twoswap; }

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

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