Submission #1013779

#TimeUsernameProblemLanguageResultExecution timeMemory
1013779vjudge1 Martian DNA (BOI18_dna)C++17
0 / 100
2045 ms9044 KiB
#include <bits/stdc++.h> #define ll long long #define pii pair<int, int> using namespace std; const int N = 2e5+5, INF = 1e9; int n, k, rr; int a[N]; int q[N]; int cur[N]; int main() { ios::sync_with_stdio(0),cin.tie(0),cout.tie(0); cin >> n >> k >> rr; for (int i = 1; i <= n; cin >> a[i++]); for (int i = 1, b; i <= rr; cin >> b >> q[b], i++); int sat = (q[a[1]] && ++cur[a[1]] == q[a[1]]); int l = 1, r = 1; int sol = INF; while (r <= n) { cerr << sat << ": " << l << ' ' << r << endl; if (sat == rr && l < r) { sol = min(sol, r-l+1); if (q[a[l]] && cur[a[l]] == q[a[l]]) sat--; cur[a[l]]--; l++; } else { r++; cur[a[r]]++; if (q[a[r]] && cur[a[r]] == q[a[r]]) sat++; } if (r == n) break; } while (l <= n && sat == rr) { sol = min(sol, r-l+1); if (q[a[l]] && cur[a[l]] == q[a[l]]) break; cur[a[l]]--; l++; } cout << (sol == INF ? "impossible" : to_string(sol)); }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...