이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pll pair<ll,ll>
#define pii pair<int,int>
#define fs first
#define sc second
string s;
int n,q;
vector<pii> req;
bool check(string &t){
vector<int> pref[n+1];
for(auto &i:pref)i = vector<int>(26,0);
for(int i = 1;i<=n;i++){
for(int j = 0;j<26;j++)pref[i][j] = pref[i-1][j];
if(t[i] != '#')pref[i][t[i]-'a']++;
}
//for(int i = 0;i<=n;i++)cout<<pref[i][0]<<' ';cout<<endl;
for(auto &i:req){
for(int j = 0;j<26;j++){
if(pref[i.sc][j]-pref[i.fs-1][j] > 1)return false;
}
}
return true;
}
int main(){
ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
cin>>s;
n = s.size();
s = "#"+s;
cin>>q;
for(int i = 0;i<q;i++){
int s,e;
cin>>s>>e;
req.push_back({s,e});
}
int mv[n+1] = {};
mv[0] = 0;
for(int i = 1;i<=n;i++)cin>>mv[i];
int l = 0,r = n;
while(l != r){
int mid = (l+r)>>1;
string t = s;
for(int j = 1;j<=mid;j++)t[mv[j]] = '#';
//cout<<mid<<":"<<t<<' '<<check(t)<<endl;
if(check(t))r = mid;
else l = mid+1;
}
cout<<l;
}
# | 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... |