# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
443398 | colossal_pepe | Grudanje (COCI19_grudanje) | C++17 | 500 ms | 11860 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) pref[i][sw.second] -= pref[i][sw.first - 1];
if (pref[i][sw.second] > 1) return 0;
}
}
return 1;
}
void solve() {
int l = 0, r = s.size();
int ans = 0;
while(l<=r){
int mid = l + (r - l)/2;
if(check(mid)){
ans = mid;
r = mid - 1;
}
else l = mid + 1;
}
cout << ans << endl;
}
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]--;
}
solve();
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... |