제출 #466317

#제출 시각아이디문제언어결과실행 시간메모리
466317popovicirobertDNA 돌연변이 (IOI21_dna)C++17
100 / 100
53 ms7444 KiB
#include "dna.h" #include <bits/stdc++.h> using namespace std; constexpr int N = (int)1e5; constexpr int SIGMA = 256; static int freq[N + 1][3][3]; static int id[SIGMA]; static int n; void init(std::string a, std::string b) { id['A'] = 0; id['C'] = 1; id['T'] = 2; n = a.size(); a = " " + a; b = " " + b; for (int i = 1; i <= n; i++) { for (int x = 0; x < 3; x++) { for (int y = 0; y < 3; y++) { freq[i][x][y] = freq[i - 1][x][y] + (id[a[i]] == x && id[b[i]] == y); } } } } int get_distance(int x, int y) { x++, y++; static int currFreq[3][3]; for (int i = 0; i < 3; i++) { for (int j = 0; j < 3; j++) { currFreq[i][j] = freq[y][i][j] - freq[x - 1][i][j]; // cerr << currFreq[i][j] << " "; } // cerr << "\n"; } // cerr << "\n"; int answer = 0; auto Update = [&answer](int id1, int id2) { int curr = min(currFreq[id1][id2], currFreq[id2][id1]); currFreq[id1][id2] -= curr; currFreq[id2][id1] -= curr; answer += curr; }; Update(0, 1); Update(1, 2); Update(0, 2); if (currFreq[0][1] != currFreq[1][2] || currFreq[1][2] != currFreq[2][0] || currFreq[0][2] != currFreq[2][1] || currFreq[2][1] != currFreq[1][0]) { return -1; } int mx = 0; for (int i = 0; i < 3; i++) { for (int j = 0; j < 3; j++) { if (i != j) { mx = max(mx, currFreq[i][j]); } } } answer += 2 * mx; // cerr << "DEBUG: " << mx << "\n"; return answer; }

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

dna.cpp: In function 'void init(std::string, std::string)':
dna.cpp:25:49: warning: array subscript has type 'char' [-Wchar-subscripts]
   25 |     freq[i][x][y] = freq[i - 1][x][y] + (id[a[i]] == x && id[b[i]] == y);
      |                                                 ^
dna.cpp:25:66: warning: array subscript has type 'char' [-Wchar-subscripts]
   25 |     freq[i][x][y] = freq[i - 1][x][y] + (id[a[i]] == x && id[b[i]] == y);
      |                                                                  ^
#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...