Submission #969165

#TimeUsernameProblemLanguageResultExecution timeMemory
969165rahidilbayramli Martian DNA (BOI18_dna)C++17
100 / 100
381 ms28180 KiB
#pragma GCC optimize("-O3") #include<bits/stdc++.h> #include<ext/pb_ds/assoc_container.hpp> #include<ext/pb_ds/tree_policy.hpp> #define ll long long #define ld long double #define vl vector<ll> #define vi vector<int> #define pii pair<int, int> #define pll pair<ll, ll> #define all(v) v.begin(), v.end() #define rall(v) v.rbegin(), v.rend() #define pb push_back #define p_b pop_back #define f first #define s second using namespace std; using namespace __gnu_pbds; typedef tree<int, null_type, less_equal<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set; void solve() { ll n, k, r, i; cin >> n >> k >> r; ll ans = LLONG_MAX; map<ll, ll>mp, mp2; vl v(n+5); for(i = 1; i <= n; i++) cin >> v[i]; for(i = 0; i < r; i++) { ll b, q; cin >> b >> q; mp[b] = q; } ll f = n - r, j = 1; for(i = 1; i <= n; i++) { mp2[v[i]]++; if(mp2[v[i]] == mp[v[i]]) f++; if(f < n) continue; while(mp2[v[j]] != mp[v[j]]) { mp2[v[j]]--; j++; } ans = min(ans, i - j + 1); } if(ans == LLONG_MAX) cout << "impossible\n"; else cout << ans << "\n"; } int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); ll tests = 1; //cin >> tests; while(tests--) { solve(); } }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...