Submission #1184004

#TimeUsernameProblemLanguageResultExecution timeMemory
1184004alterio Martian DNA (BOI18_dna)C++20
100 / 100
19 ms2632 KiB
#include <bits/stdc++.h> using namespace std; #define endl '\n' #define ll long long #define all(x) (x).begin(), (x).end() int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); int n, k, R; cin >> n >> k >> R; vector<int> v(n); for (int i = 0; i < n; i++) cin >> v[i]; vector<int> cnt(k, -1), have(k); for (int i = 0; i < R; i++) { int type, need; cin >> type >> need; cnt[type] = need; } int ok = 0, r = 0, ans = 1e9; for (int i = 0; i < n; i++) { while (r < n && ok != R) { have[v[r]]++; if (have[v[r]] == cnt[v[r]]) ok++; r++; } if (ok == R) ans = min(ans, r - i); if (have[v[i]] == cnt[v[i]]) ok--; have[v[i]]--; } 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...