이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
int main() {
ios_base :: sync_with_stdio(0);
cin.tie(0) , cout.tie(0);
string s;
cin >> s;
const int n = (int)s.size();
int q;
cin >> q;
vector<pair<int , int> > sub(q);
for (int i = 0; i < q; i++) {
int a , b;
cin >> a >> b;
sub[i] = {a , b};
}
vector<int> p(n);
for (int i = 0; i < n; i++) {
cin >> p[i];
}
auto can = [&](int tot) {
vector<bool> used(n , false);
for (int i = 0; i < tot; i++) {
used[p[i]] = true;
}
vector<vector<int> > let(n + 1 , vector<int>(26 , 0));
for (int i = 1; i <= n; i++) {
if (!used[i]) {
let[i][int(s[i - 1] - 'a')]++;
}
for (int j = 0; j < 26; j++) {
let[i][j] += let[i - 1][j];
}
}
for (int i = 0; i < q; i++) {
int L = sub[i].first , R = sub[i].second;
for (int j = 0; j < 26; j++) {
if (let[R][j] - let[L - 1][j] >= 2) {
return false;
}
}
}
return true;
};
int l = 0 , r = n;
while (l != r) {
int mid = (l + r) >> 1;
if (can(mid))
r = mid;
else
l = mid + 1;
}
cout << r << '\n';
return 0;
}
# | 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... |
# | 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... |