Submission #646621

#TimeUsernameProblemLanguageResultExecution timeMemory
646621alextodoran Martian DNA (BOI18_dna)C++17
0 / 100
69 ms20860 KiB
/** ____ ____ ____ ____ ____ ||a |||t |||o |||d |||o || ||__|||__|||__|||__|||__|| |/__\|/__\|/__\|/__\|/__\| **/ #include <bits/stdc++.h> using namespace std; typedef long long ll; const int N_MAX = 200000; const int R_MAX = 10; int N, K, R; int D[N_MAX + 2]; int B[R_MAX + 2], Q[R_MAX + 2]; int pref[R_MAX + 2][N_MAX + 2]; int main () { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); cin >> N >> K >> R; for (int i = 1; i <= N; i++) { cin >> D[i]; } for (int r = 1; r <= R; r++) { cin >> B[r] >> Q[r]; for (int i = 1; i <= N; i++) { pref[r][i] = pref[r][i - 1] + (D[i] == B[r]); } } int answer = INT_MAX; for (int i = 1; i <= N; i++) { int lo = 0, hi = i; while (lo < hi) { int mid = (lo + hi + 1) / 2; bool ok = true; for (int r = 1; r <= K; r++) { if (pref[r][i] - pref[r][mid - 1] < Q[r]) { ok = false; break; } } if (ok == true) { lo = mid; } else { hi = mid - 1; } } if (lo > 0) { answer = min(answer, i - lo + 1); } } if (answer != INT_MAX) { cout << answer << "\n"; } else { cout << "impossible\n"; } 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...