이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include<bits/stdc++.h>
using namespace std;
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define sz(a) a.size()
#define pf push_front
#define pb push_back
#define vt vector
#define s second
#define f first
#define nl '\n'
using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
string a, b;
void init(string A, string B) {
a = A, b = B;
}
int get_distance(int x, int y) {
vt<char> s;
for (int i = x; i <= y; i++)
s.pb(b[i]);
int ans = 0;
for (int i = x; i <= y; i++) {
int ps = -1;
for (int j = 0; j < sz(s); j++) {
if (s[j] == a[i]) {
ps = j;
break;
}
}
if (ps == -1) return -1;
ans++;
vt<char> h;
for (int j = 0; j < sz(s); j++) {
if (j == ps) continue;
h.pb(s[j]);
}
swap(s, h);
}
return ans;
}
#ifdef MANSUR
int main() {
int n, q;
assert(scanf("%d %d", &n, &q) == 2);
char A[n+1], B[n+1];
assert(scanf("%s", A) == 1);
assert(scanf("%s", B) == 1);
std::string a = std::string(A);
std::string b = std::string(B);
std::vector<int> x(q), y(q);
for (int i = 0; i < q; i++) {
assert(scanf("%d %d", &x[i], &y[i]) == 2);
}
fclose(stdin);
std::vector<int> results(q);
init(a, b);
for (int i = 0; i < q; i++) {
results[i] = get_distance(x[i], y[i]);
}
for (int i = 0; i < q; i++) {
printf("%d\n", results[i]);
}
return 0;
}
#endif
컴파일 시 표준 에러 (stderr) 메시지
dna.cpp: In function 'int get_distance(int, int)':
dna.cpp:32:21: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
32 | for (int j = 0; j < sz(s); j++) {
| ^
dna.cpp:41:21: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
41 | for (int j = 0; j < sz(s); j++) {
| ^
# | 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... |