# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
339694 | Hazem | Grudanje (COCI19_grudanje) | C++14 | 229 ms | 13832 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
/*
ID: tmhazem1
LANG: C++14
TASK: pprime
*/
#include <bits/stdc++.h>
using namespace std;
#define S second
#define F first
#define LL long long
const int N = 2e5 + 10;
LL LINF = 100000000000000000;
LL INF = 1000000000;
vector<pair<int,int>>vec;
int n,q;
int freq[N][26],a[N];
string s;
bool ok(int mid){
for(int i=1;i<=n;i++){
char c = a[i]<=mid?'*':s[i-1];
for(int j=0;j<26;j++)
freq[i][j] = freq[i-1][j]+(c-'a'==j);
}
bool q = 1;
for(auto x:vec)
for(int i=0;i<26;i++)
q &= freq[x.S][i]-freq[x.F-1][i]<=1;
return q;
}
int main()
{
//freopen("out.txt","w",stdout);
cin>>s;
n = s.size(),q;
scanf("%d",&q);
while(q--){
int l,r;
scanf("%d%d",&l,&r);
vec.push_back({l,r});
}
for(int i=1;i<=n;i++){
int x;cin>>x;
a[x] = i;
}
int l = 0,r = n-1;
while(l<r){
int mid = (l+r)/2;
if(ok(mid)) r = mid;
else l = mid+1;
}
printf("%d\n",l);
}
Compilation message (stderr)
# | 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... |