제출 #1067370

#제출 시각아이디문제언어결과실행 시간메모리
1067370AlgorithmWarriorDNA 돌연변이 (IOI21_dna)C++17
컴파일 에러
0 ms0 KiB
#include "dna.h" #include <bits/stdc++.h> #define MAX 100005 using namespace std; int sp[MAX][3][3]; int sp1[MAX][3]; int sp2[MAX][3]; void init(string a, string b) { int to[100]; to['A']=0; to['C']=1; to['T']=2; int n=a.size(); int i,j,k; for(i=1;i<=n;++i) { ++sp[i][to[a[i-1]]][to[b[i-1]]]; ++sp1[i][to[a[i-1]]]; ++sp2[i][to[b[i-1]]]; for(j=0;j<3;++j) sp1[i][j]+=sp1[i-1][j]; for(j=0;j<3;++j) sp2[i][j]+=sp2[i-1][j]; for(j=0;j<3;++j) for(k=0;k<3;++k) sp[i][j][k]+=sp[i-1][j][k]; } } int get_distance(int x, int y) { ++x,++y; int i,j; for(i=0;i<3;++i) if(sp1[y][i]-sp1[x-1][i]!=sp2[y][i]-sp2[x-1][i]) return -1; int nr=abs(sp[y][0][1]-sp[x-1][0][1]-sp[y][1][0]+sp[x-1][1][0]); int cnt=2*nr; for(i=0;i<3;++i) for(j=i+1;j<3;++j) cnt+=min(sp[y][i][j]-sp[x-1][i][j],sp[y][j][i]-sp[x-1][j][i]); return cnt; } int main() { int n, q; assert(scanf("%d %d", &n, &q) == 2); char A[n+1], B[n+1]; assert(scanf("%s", A) == 1); assert(scanf("%s", B) == 1); std::string a = std::string(A); std::string b = std::string(B); std::vector<int> x(q), y(q); for (int i = 0; i < q; i++) { assert(scanf("%d %d", &x[i], &y[i]) == 2); } fclose(stdin); std::vector<int> results(q); init(a, b); for (int i = 0; i < q; i++) { results[i] = get_distance(x[i], y[i]); } for (int i = 0; i < q; i++) { printf("%d\n", results[i]); } fclose(stdout); return 0; }

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

dna.cpp: In function 'void init(std::string, std::string)':
dna.cpp:21:26: warning: array subscript has type 'char' [-Wchar-subscripts]
   21 |         ++sp[i][to[a[i-1]]][to[b[i-1]]];
      |                          ^
dna.cpp:21:38: warning: array subscript has type 'char' [-Wchar-subscripts]
   21 |         ++sp[i][to[a[i-1]]][to[b[i-1]]];
      |                                      ^
dna.cpp:22:27: warning: array subscript has type 'char' [-Wchar-subscripts]
   22 |         ++sp1[i][to[a[i-1]]];
      |                           ^
dna.cpp:23:27: warning: array subscript has type 'char' [-Wchar-subscripts]
   23 |         ++sp2[i][to[b[i-1]]];
      |                           ^
/usr/bin/ld: /tmp/ccjiKrkg.o: in function `main':
grader.cpp:(.text.startup+0x0): multiple definition of `main'; /tmp/cc9DYOMg.o:dna.cpp:(.text.startup+0x0): first defined here
collect2: error: ld returned 1 exit status