제출 #1141907

#제출 시각아이디문제언어결과실행 시간메모리
1141907jjjj1DNA 돌연변이 (IOI21_dna)C++20
0 / 100
20 ms4680 KiB
#include <bits/stdc++.h> #include "dna.h" #define sz(a) (int)(a).size() using namespace std; const int N = 100'001; int cntA[N][3], cntB[N][3]; string A, B; int sum(int ch, int x, int y, bool A){ if (A) return cntA[y][ch]-(x == 0 ? 0 : cntA[x-1][ch]); else return cntB[y][ch]-(x == 0 ? 0 : cntB[x-1][ch]); } int ord(char c){ // index by char if (c == 'A') return 0; else if (c == 'T') return 1; else return 2; } bool check(int x, int y){ for (int i=0;i<3;i++){ int sumA = sum(i, x, y, true); int sumB = sum(i, x, y, false); if (sumA != sumB){ return false; } } return true; } void init(string a, string b) { A = a, B = b; memset(cntA, 0, sizeof(cntA)); memset(cntB, 0, sizeof(cntB)); // prefsum precomputation int n = sz(a); for (int i=0;i<n;i++){ // string a cntA[i][0] = (i == 0 ? 0 : cntA[i-1][0]) + (ord(a[i]) == 0); cntA[i][1] = (i == 0 ? 0 : cntA[i-1][1]) + (ord(a[i]) == 1); cntA[i][2] = (i == 0 ? 0 : cntA[i-1][2]) + (ord(a[i]) == 2); // string b cntB[i][0] = (i == 0 ? 0 : cntB[i-1][0]) + (ord(b[i]) == 0); cntB[i][1] = (i == 0 ? 0 : cntB[i-1][1]) + (ord(b[i]) == 1); cntB[i][2] = (i == 0 ? 0 : cntB[i-1][2]) + (ord(b[i]) == 2); } } int subtask1(int x, int y){ int size = y-x+1; if (size == 1) return 0; if (size == 2){ return A[x] == B[x] ? 0 : 1; } else { int diff=0; for (int i=x;i<=y;i++){ diff += (A[i] == B[i] ? 0 : 1); } return diff/2; } } int get_distance(int x, int y) { bool possible = check(x,y); if (!possible){ return -1; } if (y-x <= 2){ return subtask1(x, y); } else { return 0; } }
#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...