Submission #643511

#TimeUsernameProblemLanguageResultExecution timeMemory
643511makanhulia Martian DNA (BOI18_dna)C++17
68 / 100
2091 ms8936 KiB
#include <bits/stdc++.h> using namespace std; const int N = 2e5 + 5; int n, k, r, a[N], b[N], t[N], sum[N][10]; bool ok(int x, int y) { for(int i = 0; i < r; i++) { int s = sum[y][i] - (x == 0 ? 0 : sum[x - 1][i]); if(s < b[i]) { return 0; } } return 1; } int main() { cin.tie(0); ios_base::sync_with_stdio(0); cin >> n >> k >> r; for(int i = 0; i < n; i++) cin >> a[i]; for(int i = 0; i < r; i++) { int x, v; cin >> x >> v; b[i] = v; t[i] = x; } for(int i = 0; i < n; i++) { for(int j = 0; j < r; j++) { if(i > 0) sum[i][j] = sum[i - 1][j]; sum[i][j] += (a[i] == t[j]); } } int ans = 1e9; for(int i = 0; i < n; i++) { int l = i, r = n - 1, z = -1; while(l <= r) { int mid = (l + r) / 2; if(ok(i, mid)) { r = mid - 1, z = mid; } else { l = mid + 1; } } if(z != -1) ans = min(ans, z - i + 1); } if(ans == 1e9) { cout << "impossible"; } else { cout << ans; } }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...