Submission #1142010

#TimeUsernameProblemLanguageResultExecution timeMemory
1142010rayankMutating 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;
}

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

	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/cclmskGH.o: in function `main':
grader.cpp:(.text.startup+0x0): multiple definition of `main'; /tmp/cczRPCfm.o:dna.cpp:(.text.startup+0x0): first defined here
collect2: error: ld returned 1 exit status