이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#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
*/
컴파일 시 표준 에러 (stderr) 메시지
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 |
---|
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... |