# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
481171 | rainboy | Grudanje (COCI19_grudanje) | C11 | 41 ms | 2972 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 <stdio.h>
#include <string.h>
#define N 100000
#define Q 100000
#define A 26
int min(int a, int b) { return a < b ? a : b; }
int max(int a, int b) { return a > b ? a : b; }
char cc[N + 1]; int pp[N], ll[N], n;
int solve(int k) {
static int prev[A];
int i, j;
memset(prev, -1, A * sizeof *prev);
for (j = 0, i = -1; j < n; j++) {
int a;
if (pp[j] <= k)
continue;
a = cc[j] - 'a';
i = max(i, prev[a]);
prev[a] = j;
if (ll[j] <= i)
return 0;
}
return 1;
}
int main() {
int q, i, j, p, lower, upper;
scanf("%s%d", cc, &q), n = strlen(cc);
for (i = 0; i < n; i++)
ll[i] = i;
while (q--) {
scanf("%d%d", &i, &j), i--, j--;
ll[j] = min(ll[j], i);
}
for (p = 1; p <= n; p++) {
scanf("%d", &i), i--;
pp[i] = p;
}
lower = -1, upper = n;
while (upper - lower > 1) {
int k = (lower + upper) / 2;
if (solve(k))
upper = k;
else
lower = k;
}
printf("%d\n", upper);
return 0;
}
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... |