이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
int main() {
string s;
cin >> s;
int n = s.size(), q;
cin >> q;
s = "." + s;
vector<int> L(q), R(q);
for(int i=0; i<q; i++) cin >> L[i] >> R[i];
vector<int> v(n+1);
for(int i=1; i<=n; i++) cin >> v[i];
int l=0, r=n, ans=0;
while(l <= r) {
int mid = (l + r) / 2;
int pref[26][n+1];
memset(pref, 0, sizeof(pref));
vector<bool> bad(n+1);
for(int i=1; i<=mid; i++) bad[v[i]] = 1;
for(int i=1; i<=n; i++) {
for(int j=0; j<26; j++) pref[j][i] = pref[j][i-1];
if(!bad[i]) pref[s[i]-'a'][i]++;
}
bool ok = 1;
for(int i=0; i<q; i++)
for(int j=0; j<26; j++)
if(pref[j][R[i]] - pref[j][L[i]-1] > 1) ok = 0;
if(ok) 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... |