This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
// "Say:He is the Most Merciful,We have believed in him and upon him we have relied" [67:29]
#include<bits/stdc++.h>
using namespace std;
int main(){
string s; cin >> s;
int q, n = s.size(); cin >> q;
vector<pair<int,int>>subwords;
for(int i=0; i<q; i++){
int x, y; cin >> x >> y;
subwords.push_back({x, y});
}
vector<int>v(n);
for(int &i:v){
cin >> i;
}
string ss = s;
int l = 0, r = n, ans = n+2;
while(l <= r){
int mid = (l+r)>>1;
for(int i=0; i<mid; i++){
s[v[i]-1] = '*';
}
vector<vector<int>>cnt(26, vector<int>(n));
for(int i=0; i<26; i++){
cnt[i][0] = (s[0] == i+'a');
for(int j=1; j<n; j++){
cnt[i][j] = cnt[i][j-1] + (s[j] == i+'a');
}
}
int flag = 0;
for(auto [first, second]:subwords){
first--, second--;
if(first == 0){
for(int i=0; i<26; i++){
if(cnt[i][second] > 1){
flag = 1;
}
}
}else {
for(int i=0; i<26; i++){
if(cnt[i][second] - cnt[i][first-1] > 1){
flag = 1;
}
}
}
}
if(flag == 1){
l = mid + 1;
}else {
ans = min(ans, mid);
r = mid - 1;
}
s = ss;
}
cout << ans << '\n';
return 0;
}
Compilation message (stderr)
grudanje.cpp: In function 'int main()':
grudanje.cpp:34:12: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
34 | for(auto [first, second]:subwords){
| ^
# | 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... |