# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
198517 | ZwariowanyMarcin | Grudanje (COCI19_grudanje) | C++17 | 167 ms | 4220 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>
#define fi first
#define se second
#define mp make_pair
#define ss(x) (int) x.size()
#define pb push_back
#define LL long long
#define ld long double
#define cat(x) cerr << #x << " = " << x << endl
#define FOR(i, j, n) for(int i = j; i <= n; ++i)
#define boost cin.tie(0), ios_base::sync_with_stdio(0);
using namespace std;
const int N = 100100;
int n, q;
char s[N];
int l[N], r[N];
int p[N];
int w[N];
int pref[N];
bool ok(int k) {
for (int c = 0; c < 26; ++c) {
for (int i = 1; i <= n; ++i) {
pref[i] = pref[i - 1];
pref[i] += ((s[i] - 'a' == c) && w[i] > k);
}
for (int i = 1; i <= q; ++i)
if (pref[r[i]] - pref[l[i] - 1] > 1) return 0;
}
return 1;
}
int main() {
scanf ("%s", s + 1);
n = strlen(s + 1);
scanf ("%d", &q);
for (int i = 1; i <= q; ++i)
scanf ("%d %d", l + i, r + i);
for (int i = 1; i <= n; ++i) {
scanf ("%d", p + i);
w[p[i]] = i;
}
int l = 0;
int r = n;
while (l < r) {
int m = (l + r) / 2;
if (ok(m))
r = m;
else
l = m + 1;
}
printf ("%d", l);
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... |