Submission #1033480

#TimeUsernameProblemLanguageResultExecution timeMemory
1033480PokemonMasterMutating DNA (IOI21_dna)C++17
Compilation error
0 ms0 KiB
#include<bits/stdc++.h> using namespace std; #include "dna.h" #include <cstdio> #include <cassert> #include <string> #include <vector> void init(string a,string b) { cin>>a>>b; } int get_distance(int x,int y) { string na="",nb=""; map <char,int> mp1,mp2; for(int i=x;i<=y;i++) { na+=a[i]; nb+=b[i]; } string ca=na,cb=nb; sort(ca.begin(),ca.end()); sort(cb.begin(),cb.end()); if(ca!=cb) { return -1; } int cnt=0,res=0; while(na!=nb) { int ind=0; for(int j=cnt;j<=n;j++) { if(na[j]==nb[cnt]) { ind=j; break; } } while(ind!=cnt) { swap(na[ind],na[ind-1]); ind--; res++; } cnt++; } return res; } 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; }

Compilation message (stderr)

dna.cpp: In function 'int get_distance(int, int)':
dna.cpp:18:17: error: 'a' was not declared in this scope
   18 |             na+=a[i];
      |                 ^
dna.cpp:19:17: error: 'b' was not declared in this scope
   19 |             nb+=b[i];
      |                 ^
dna.cpp:32:30: error: 'n' was not declared in this scope
   32 |             for(int j=cnt;j<=n;j++)
      |                              ^