Submission #1141956

#TimeUsernameProblemLanguageResultExecution timeMemory
1141956rayankMutating DNA (IOI21_dna)C++20
Compilation error
0 ms0 KiB
#include "dna.h"
#include <bits/stdc++.h>
using namespace std;
string A;
string B;
void init(string a, string b) {
	A = a;
	B = b;
}

int find_pos(char c, string s, int start, int end){
	for(int i = start; i <= end; i++){
		if(s[i] == c){
			return i;
		}
	}
	return -1;
}
bool issamee(string a, string b, int start, int end){
	for(int i = start; i <= end; i++){
		if(a[i] != b[i]){
			return false;
		}
	}
	return true;
}

int get_distance(int x, int y) {
	int res = 0;
	string suba = A.substr(x, y);
	string subb = B.substr(x,y);
	string acopy = A;
	sort(suba.begin(), suba.end());
	sort(subb.begin(), subb.end());
	if(suba != subb){
		return -1;
	}
	for(int i=x; i <=y;i++){
		if(acopy[i] == B[i]) continue;
		int pos = find_pos(acopy[i], B, x, y);
		if(pos == -1) return -1;
		swap(acopy[i], acopy[pos]);
		res++;
	}

	if(!issamee(acopy, B, x, y)) return -1;
	return res;
}


int main() {
  int n,q;
  cin>>n>>q;
  string a,b;
  cin>>a>>b;
  init(a,b);
  while(q--){
      int x,y;
      cin>>x>>y;
      cout<<get_distance(x,y)<<endl;
  }
}

Compilation message (stderr)

/usr/bin/ld: /tmp/cc1J5csN.o: in function `main':
grader.cpp:(.text.startup+0x0): multiple definition of `main'; /tmp/ccniCWk5.o:dna.cpp:(.text.startup+0x0): first defined here
collect2: error: ld returned 1 exit status