Submission #927198

#TimeUsernameProblemLanguageResultExecution timeMemory
927198vjudge1 Martian DNA (BOI18_dna)C++17
100 / 100
24 ms5108 KiB
// #pragma GCC target ("avx2") // #pragma GCC optimization ("O3") // #pragma GCC optimization ("unroll-loops") #include <bits/stdc++.h> #define int long long #define ff first #define ss second #define pb push_back #define yes cout<<"Yes\n" #define no cout<<"No\n" #define no1 cout<<"-1\n" using namespace std; const int N = 2e5+100; const int M = 1e5+10; const int INF = 1e18; const int mod = 1e9+7; // int binpow (int a, int n) { // if (n == 0) // return 1; // if (n % 2 == 1) // return (binpow (a, n-1) * a)%mod; // else { // int b = binpow (a, n/2); // return (b * b)%mod; // } // } int n,k,R; int a[N]; int b[N]; int cnt[N]; void solve(){ cin>>n>>k>>R; for(int i = 1;i<=n;i++){ cin>>a[i]; } for(int i = 1;i<=R;i++){ int x,q; cin>>x>>q; b[x] = q; } int c = 0; int l = 1; int ans = INF; for(int r = 1;r<=n;r++){ cnt[a[r]]++; if(cnt[a[r]] == b[a[r]] && b[a[r]] != 0) c++; while(l<r && cnt[a[l]]-1 >= b[a[l]]){ cnt[a[l]]--; l++; } if(c == R) ans = min(ans,r-l+1); } if(ans == INF) cout<<"impossible\n"; else cout<<ans<<'\n'; } signed main(){ ios_base::sync_with_stdio(0); cin.tie(nullptr); // cout.tie(nullptr); int t = 1; // cin>>t; // cout<<""; for(int i = 1;i<=t;i++){ // cout<<"Case "<<i<<": "; solve(); // cout<<'\n'; } }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...