Submission #541840

# Submission time Handle Problem Language Result Execution time Memory
541840 2022-03-24T14:19:16 Z YassineBenYounes Mutating DNA (IOI21_dna) C++17
0 / 100
23 ms 3724 KB
#include<bits/stdc++.h>
using namespace std;
 
typedef long long ll;
 
#define vi vector<int>
#define vll vector<pair<ll, ll>>
#define vii vector<pair<int, int>>
#define pb push_back
#define ff first
#define ss second
 
string a, b;
int n, q;
 
int get_distance(int x, int y);
 
void init(string a, string b){
    cin >> n >> q;
    cin >> a >> b;
    while(q--){
        int x, y;cin >> x >> y;
        cout << get_distance(x, y) << endl;
    }
}
 
int get_distance(int x, int y){
    string one = a.substr(x, y - x + 1);
    string two = b.substr(x, y - x + 1);
    int c = 0;
    for(int i = 0; i < one.size();i++){
        if(one[i] != two[i]){
            int index = -1;
            for(int x = i + 1; x < one.size();x++){
                if(one[x] == two[i]){
                    index = x;break;
                }
            }
            if(index == -1)return -1;
            else{
                swap(one[i], one[index]);
                c++;
            }
        }
    }
    return c;
}
/*
5
1
ATACAT
ACTATA
1 3
*/

Compilation message

dna.cpp: In function 'int get_distance(int, int)':
dna.cpp:31:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   31 |     for(int i = 0; i < one.size();i++){
      |                    ~~^~~~~~~~~~~~
dna.cpp:34:34: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   34 |             for(int x = i + 1; x < one.size();x++){
      |                                ~~^~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Runtime error 23 ms 3724 KB Execution killed with signal 6
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 3 ms 468 KB Execution killed with signal 6
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 3 ms 468 KB Execution killed with signal 6
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 3 ms 468 KB Execution killed with signal 6
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 23 ms 3724 KB Execution killed with signal 6
2 Halted 0 ms 0 KB -