제출 #531180

#제출 시각아이디문제언어결과실행 시간메모리
531180jamezzzDNA 돌연변이 (IOI21_dna)C++17
100 / 100
39 ms7296 KiB
#include "dna.h" #include <bits/stdc++.h> using namespace std; int n; int pfx[100005][6],pa[100005][3],pb[100005][3],cnt[6]; int to(char c){ if(c=='A')return 0; else if(c=='C')return 1; else return 2; } void init(string a,string b){ n=a.length(); for(int i=1;i<=n;++i){ for(int j=0;j<3;++j){ pa[i][j]=pa[i-1][j]; pb[i][j]=pb[i-1][j]; } ++pa[i][to(a[i-1])]; ++pb[i][to(b[i-1])]; } for(int i=0;i<n;++i){ for(int j=0;j<6;++j){ pfx[i+1][j]=pfx[i][j]; } int v; if(a[i]==b[i])continue; if(a[i]=='C'&&b[i]=='A')v=0; if(a[i]=='T'&&b[i]=='A')v=1; if(a[i]=='A'&&b[i]=='C')v=2; if(a[i]=='T'&&b[i]=='C')v=3; if(a[i]=='A'&&b[i]=='T')v=4; if(a[i]=='C'&&b[i]=='T')v=5; ++pfx[i+1][v]; } } int get_distance(int x,int y){ ++x;++y; bool pos=true; for(int i=0;i<3;++i)pos=pos&&(pa[y][i]-pa[x-1][i]==pb[y][i]-pb[x-1][i]); if(!pos)return -1; for(int i=0;i<6;++i)cnt[i]=pfx[y][i]-pfx[x-1][i]; int t,ans=0; t=min(cnt[0],cnt[2]); cnt[0]-=t;cnt[2]-=t;ans+=t; t=min(cnt[1],cnt[4]); cnt[1]-=t;cnt[4]-=t;ans+=t; t=min(cnt[3],cnt[5]); cnt[3]-=t;cnt[5]-=t;ans+=t; ans+=2*(cnt[0]+cnt[2]); return ans; }

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

dna.cpp: In function 'void init(std::string, std::string)':
dna.cpp:37:15: warning: 'v' may be used uninitialized in this function [-Wmaybe-uninitialized]
   37 |   ++pfx[i+1][v];
      |     ~~~~~~~~~~^
#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...