# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
443428 | colossal_pepe | Grudanje (COCI19_grudanje) | C++17 | 480 ms | 13776 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 <iostream>
#include <vector>
#include <cstring>
using namespace std;
string s;
int q, snowballs[100005];
vector<pair<int, int>> subwords;
bool check(int g) {
int pref[26][s.size()];
memset(pref, 0, sizeof(pref));
for (int i = 0; i < s.size(); i++) {
pref[s[i] - 'a'][i] = 1;
}
for (int i = 0; i < g; i++) {
pref[s[snowballs[i]] - 'a'][snowballs[i]] = 0;
}
for (int i = 0; i < 26; i++) {
for (int j = 1; j < s.size(); j++) {
pref[i][j] += pref[i][j - 1];
}
}
for (pair<int, int> sw: subwords) {
for (int i = 0; i < 26; i++) {
if (sw.first > 0) {
if (pref[i][sw.second] - pref[i][sw.first - 1] > 1) return 0;
} else {
if (pref[i][sw.second] > 1) return 0;
}
}
}
return 1;
}
int solve() {
int l = 0, r = s.size();
while (r - l > 5) {
int mid = (l + r)/2;
if (check(mid)) r = mid;
else l = mid;
}
for (int i = l; i <= r; i++) {
if (check(i)) return i;
}
return r;
}
int main() {
cin >> s >> q;
subwords.resize(q);
for (int i = 0; i < q; i++) {
cin >> subwords[i].first >> subwords[i].second;
subwords[i].first--, subwords[i].second--;
}
for (int i = 0; i < s.size(); i++) {
cin >> snowballs[i];
snowballs[i]--;
}
cout << solve() << endl;
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... |