This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
/**
* author: mahfuzz
* created: 12.07.2021
**/
#include <bits/stdc++.h>
using namespace std;
#define trace(x) cerr << '>' << #x << ':' << x << endl;
#define all(p) p.begin(),p.end()
typedef long long ll;
#define pii pair<int, int>
int main(int argc, char* argv[]){
ios_base::sync_with_stdio(0);
cin.tie(nullptr);
string s; cin >> s;
int n = s.size();
int q; cin >> q;
vector<pii> vec;
for(int i = 0; i < q; i++){
int l, r; cin >> l >> r;
vec.push_back({l, r});
}
int arr[n];
for(int i = 0; i < n; i++)
cin >> arr[i];
auto check = [&](int x){
string temp = s;
for(int k = 0; k < x; k++){
temp[arr[k] - 1] = '*';
}
int g[26][26] = {{0}};
for(int i = 0; i < 26; i++){
char c = 'a' + i;
g[i][0] = (temp[0] == c);
for(int j = 1; temp[j]; j++){
g[i][j] = g[i][j - 1] + (temp[j] == c);
}
}
for(auto a : vec){
int l = a.first, r = a.second;
for(int i = 0; i < 26; i++){
if(l - 2 < 0){
if(g[i][r - 1] > 1)
return false;
}else if(g[i][r - 1] - g[i][l - 2] > 1)
return false;
}
}
return true;
};
if(check(0)){
cout << "0\n";
return 0;
}
int l = 1, r = n;
int ans = 0;
while(l <= r){
int mid = (l + r) / 2;
if(check(mid)){
ans = mid;
r = mid - 1;
}else{
l = mid + 1;
}
}
cout << ans << "\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... |