(UPD: 2024-12-04 14:48 UTC) Judge is not working due to Cloudflare incident. (URL) We can do nothing about it, sorry. After the incident is resolved, we will grade all submissions.

Submission #229227

#TimeUsernameProblemLanguageResultExecution timeMemory
229227VEGAnnGrudanje (COCI19_grudanje)C++14
70 / 70
131 ms14020 KiB
#include <bits/stdc++.h> #define sz(x) ((int)x.size()) using namespace std; const int N = 100100; string s; int n, p[N], l[N], r[N], sf[N][26], q; bool mrk[N]; bool ok(int x){ fill(mrk, mrk + n, 0); for (int i = 0; i < x; i++) mrk[p[i]] = 1; fill(sf[n], sf[n] + 26, 0); for (int i = n - 1; i >= 0; i--){ for (int j = 0; j < 26; j++) sf[i][j] = sf[i + 1][j]; if (!mrk[i]) sf[i][s[i] - 'a']++; } for (int i = 0; i < q; i++) for (int j = 0; j < 26; j++) if (sf[l[i]][j] - sf[r[i]][j] > 1) return 0; return 1; } int main(){ ios_base::sync_with_stdio(0); cin.tie(0); // freopen("in.txt","r",stdin); cin >> s; n = sz(s); cin >> q; for (int i = 0; i < q; i++){ cin >> l[i] >> r[i]; l[i]--; } for (int i = 0; i < n; i++){ cin >> p[i]; p[i]--; } int l1 = 0, r1 = n; while (l1 < r1){ int md = (l1 + r1) >> 1; if (ok(md)) r1 = md; else l1 = md + 1; } cout << l1; return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...