Submission #939432

#TimeUsernameProblemLanguageResultExecution timeMemory
939432Gromp15 Martian DNA (BOI18_dna)C++17
100 / 100
25 ms4688 KiB
#include <bits/stdc++.h> #define ll long long #define ar array #define db double #define all(x) x.begin(), x.end() #define sz(x) (int)x.size() using namespace std; mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); #define rint(l, r) uniform_int_distribution<int>(l, r)(rng) template<typename T> bool ckmin(T &a, const T &b) { return a > b ? a = b, 1 : 0; } template<typename T> bool ckmax(T &a, const T &b) { return a < b ? a = b, 1 : 0; } void test_case() { int n, k, m; cin >> n >> k >> m; vector<int> req(k), a(n); for (int &x : a) cin >> x; for (int i = 0; i < m; i++) { int x, y; cin >> x >> y; req[x] = y; } int good = k - m, to = -1; vector<int> have(k); int ans = 1e9; for (int i = 0; i < n; i++) { while (good < k && to+1 < n) { if (++have[a[to+1]] == req[a[to+1]]) { good++; } to++; } if (good == k) { ckmin(ans, to - i + 1); } else break; assert(have[a[i]] >= req[a[i]]); if (have[a[i]]-- == req[a[i]]) good--; } if (ans == 1e9) cout << "impossible\n"; else cout << ans << '\n'; } int main() { cin.tie(0)->sync_with_stdio(0); int t = 1; // cin >> t; while (t--) test_case(); }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...