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 <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... |