Submission #382490

#TimeUsernameProblemLanguageResultExecution timeMemory
382490vishesh312 Martian DNA (BOI18_dna)C++17
0 / 100
32 ms2540 KiB
#include "bits/stdc++.h" using namespace std; /* #include <ext/pb_ds/assoc_container.hpp> using namespace __gnu_pbds; using ordered_set = tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update>; */ #define all(x) begin(x), end(x) #define sz(x) (int)x.size() using ll = long long; #define int ll const int mod = 1e9+7; void solve(int tc) { int n, k, r; cin >> n >> k >> r; vector<int> v(n); for (auto &x : v) cin >> x; vector<int> a(k); int req = 0; for (int i = 0; i < r; ++i) { int x, y; cin >> x >> y; a[x] += y; req += y; } if (a[v[0]] >0) --req; a[v[0]]--; int l = 0; r = 0; int ans = mod; while (r < n-1) { while (req == 0) { ans = min(ans, r-l+1); if (a[v[l]] >= 0) req++; a[v[l]]++; } while (req > 0 and r+1 < n) { ++r; if (a[v[r]] > 0) --req; a[v[r]]--; } if (req == 0) ans = min(ans, r-l+1); } if (ans >= mod) cout << "impossible\n"; cout << ans << '\n'; } signed main() { ios_base::sync_with_stdio(false); cin.tie(NULL); int tc = 1; //cin >> tc; for (int i = 1; i <= tc; ++i) solve(i); 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...