# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
206149 | luciocf | Grudanje (COCI19_grudanje) | C++14 | 343 ms | 13944 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.
#include <bits/stdc++.h>
using namespace std;
typedef pair<int, int> pii;
const int maxn = 1e5+10;
int n, q;
string a;
int p[maxn];
int pref[28][maxn];
bool mark[maxn];
pii range[maxn];
bool ok(int t)
{
memset(mark, 0, sizeof mark);
for (int i = 1; i <= t; i++)
mark[p[i]] = 1;
for (int c = 0; c < 26; c++)
{
for (int i = 1; i <= n; i++)
{
if (mark[i] || a[i-1] != (char)(c+'a')) pref[c][i] = pref[c][i-1];
else pref[c][i] = pref[c][i-1]+1;
}
}
for (int i = 1; i <= q; i++)
{
bool ok = 1;
for (int c = 0; c < 26; c++)
if (pref[c][range[i].second]-pref[c][range[i].first-1] > 1)
ok = 0;
if (!ok) return false;
}
return true;
}
int busca(void)
{
int ini = 0, fim = n, ans = n;
while (ini <= fim)
{
int mid = (ini+fim)>>1;
if (ok(mid)) ans = mid, fim = mid-1;
else ini = mid+1;
}
return ans;
}
int main(void)
{
cin >> a;
n = a.size();
scanf("%d", &q);
for (int i = 1; i <= q; i++)
scanf("%d %d", &range[i].first, &range[i].second);
for (int i = 1; i <= n; i++)
scanf("%d", &p[i]);
printf("%d\n", busca());
}
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... |