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 pb push_back
using namespace std;
typedef long long ll;
string a;
int q, n, d[100001], suffix_arr[26][100001];
pair <int, int> query[100001];
bool ok(int x) {
string z = a;
for (int i = 1; i <= x; ++ i) {
z[d[i]] = '*';
}
// cout << z << endl;
for (int i = 0; i <= 25; ++ i)
suffix_arr[i][0] = 0;
for (int i = 1; i <= n; ++ i) {
for (int j = 0; j <= 25; ++ j)
suffix_arr[j][i] = 0;
if (z[i] != '*') {
suffix_arr[int(z[i] - 'a')][i] = 1;
}
for (int j = 0; j <= 25; ++ j) {
suffix_arr[j][i] += suffix_arr[j][i-1];
}
}
for (int i = 1; i <= q; ++ i) {
for (int j = 0; j <= 25; ++ j) {
if (suffix_arr[j][query[i].se] - suffix_arr[j][query[i].fi - 1] > 1) return false;
}
}
return true;
}
int main() {
//freopen(".INP", "r", stdin);
//freopen(".OUT", "w", stdout);
ios_base::sync_with_stdio(false);
cin.tie(NULL); cout.tie(NULL);
cin >> a;
n = a.size();
a = '0' + a;
cin >> q;
for (int i = 1; i <= q; ++ i) {
cin >> query[i].fi >> query[i].se;
}
for (int i = 1; i <= n; ++ i) {
cin >> d[i];
}
int l = 0, r = n, ans;
while (l <= r) {
int mid = (l + r) / 2;
if (ok(mid)) {
r = mid - 1;
ans = mid;
}
else l = mid + 1;
}
cout << ans;
return 0;
}
Compilation message (stderr)
grudanje.cpp: In function 'int main()':
grudanje.cpp:69:13: warning: 'ans' may be used uninitialized in this function [-Wmaybe-uninitialized]
69 | cout << ans;
| ^~~
# | 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... |