This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include "dna.h"
#include <bits/stdc++.h>
#define all(s) s.begin(), s.end()
using namespace std;
string a, b;
int n;
void init(string _a, string _b)
{
a = _a;
b = _b;
n = a.size();
}
int get_distance(int x, int y)
{
string sub_a = string(a.begin() + x, a.begin() + y + 1);
string sub_b = string(b.begin() + x, b.begin() + y + 1);
if (sub_a == sub_b)
return 0;
// sub_a != sub_b
if (sub_a.size() == 1)
return -1;
if (sub_a.size() == 2)
{
sort(all(sub_a));
sort(all(sub_b));
if (sub_a != sub_b)
return -1;
else
return 1;
}
// sub.size() == 3
string oa = sub_a;
string ob = sub_b;
sort(all(sub_a));
sort(all(sub_b));
if (sub_a != sub_b)
return -1;
// counts tan bien
int eq = 0;
for (int i = 0; i < 3; i++)
{
eq += oa[i] == ob[i];
}
switch (eq)
{
case 0:
return 2;
case 1:
return 1;
default:
return -2; // explode
}
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |