제출 #470083

#제출 시각아이디문제언어결과실행 시간메모리
470083MohamedAliSaidaneDNA 돌연변이 (IOI21_dna)C++17
100 / 100
56 ms10384 KiB
#include <bits/stdc++.h> #include "dna.h" using namespace std; typedef pair<int,int> pii; typedef vector<int> vi; typedef long long ll; typedef pair<ll,ll> pll; typedef tuple<int,int,int> ti; typedef unsigned long long ull; typedef long double ld; typedef vector<ll> vll; typedef pair<ld,ld> pld; #define pb push_back #define popb pop_back() #define pf push_front #define popf pop_front #define ff first #define ss second #define MOD (int)(1e8) #define INF (ll) (1e18) #define all(v) (v).begin(),(v).end() ll gcd(ll a , ll b) {return b ? gcd(b , a % b) : a ;} ll lcm(ll a , ll b) {return (a * b) / gcd(a , b);} ld pointdist(ld x, ld y, ld point) { return ((x-point)*(y-point))/abs(x-y); } //ld dist(ld x, ld y, ld a, ld b){ return sqrt((x-a)*(x-a) + (y-b)*(y-b)); } const int nx[8] = {0, 0, 1, -1,1,1,-1,-1}, ny[8] = {1, -1, 0, 0,1,-1,1,-1}; //East, West, South, North+ ////////////******SOLUTION******\\\\\\\\\\\ const int MAX_N = 1e5 + 4; string a, b; int n; int Apref[MAX_N][3]; int Bpref[MAX_N][3]; int cross[MAX_N][3][3]; int error[MAX_N]; char ar[3] = {'A','C','T'}; void build() { for(int k = 0; k < 3; k ++) { Apref[0][k] = Bpref[0][k] = 0; for(int i = 0; i <n; i ++) { Apref[i+1][k] = Apref[i][k] + (a[i] == ar[k]); Bpref[i+1][k] = Bpref[i][k] + (b[i] == ar[k]); } } for(int j = 0; j < 3; j ++) { for(int k = 0; k < 3; k ++) { if(j == k) continue; for(int i = 0; i <n; i ++) cross[i+1][j][k] = cross[i][j][k] + (a[i] == ar[j] && b[i] == ar[k]); } } for(int i = 0; i <n; i ++) error[i+1] = error[i] + (a[i] != b[i]); } void init(string ab, string bb) { a = ab; b = bb; n = a.length(); build(); } int get_distance(int l, int r) { for(int k = 0; k < 2; k ++) if(Apref[r+1][k] - Apref[l][k] != Bpref[r+1][k] - Bpref[l][k]) return -1; int faux = error[r+1] - error[l]; int dv = 0; for(int j = 0; j <2; j ++) { for(int k = j+1; k <3; k ++) { int bg= min(cross[r+1][j][k] - cross[l][j][k], cross[r+1][k][j] - cross[l][k][j]); bg *= 2; dv += bg; //cout << ar[j] << ' ' << ar[k] << ' ' << bg << '\n'; } } int cost = dv/2 + ((faux-dv)*2)/3 + ((faux-dv)%3 != 0); return cost; } /*int main() { ios::sync_with_stdio(false); cin.tie(0); cout.tie(0); int p, q; cin >> p >> q; string x, y; cin >> x >> y; init(x,y); while(q--) { int u, v; cin >> u >> v; cout << get_distance(u,v) << '\n' ; } /*for(int i = 1; i <=n; i ++) { for(int j = 0; j < 3; j ++) { for(int k = 0; k <3;k ++) { if(j == k) continue; cout << ar[j] << '_' << ar[k] << ":" << cross[i][j][k] << ' '; } } cout << '\n'; } } /* 6 3 ATACAT ACTATA" 1 3 4 5 3 5 */ /* Identify problem diagram: Brute force, Greedy, Dynamic Programming, Divide and Conquer Reformulate the problem into something more theoretical !!!!! IMPLICIT GRAPH ?????? !!!!! PAY ATTENTION TO THE CONSTRAINTS: DP nD ? BF ? BITMASKING ? !!!!! SOLVE THE SUBTASKS FIRST: IT'S TOTALLY OK NOT TO SOLVE THE PROBLEM ENTIRELY Search for multiple approaches: select the seemingly optimal one Remember that you're the king of CP Change your approach Imagine Corner cases before submitting Don't spend too much time on the problem: move on ! */

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

dna.cpp:27:1: warning: multi-line comment [-Wcomment]
   27 | ////////////******SOLUTION******\\\\\\\\\\\
      | ^
dna.cpp:100:5: warning: "/*" within comment [-Wcomment]
  100 |     /*for(int i = 1; i <=n; i ++)
      |      
dna.cpp:113:1: warning: "/*" within comment [-Wcomment]
  113 | /*
      |
#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...