Submission #453699

#TimeUsernameProblemLanguageResultExecution timeMemory
453699Blobo2_Blobo2 Martian DNA (BOI18_dna)C++17
100 / 100
45 ms4468 KiB
/* Editor: Abdelrahman Hossam Nickname: Blobo2_Blobo2 IOI next year isA :) */ /*#pragma GCC optimize("Ofast,no-stack-protector,unroll-loops,fast-math,O3") #pragma GCC target("sse,sse2,sse3,ssse3,sse4,sse4.2,popcnt,abm,mmx,avx2,tune=native") #pragma GCC optimize("-ffast-math") #pragma GCC optimize("-funroll-loops") #pragma GCC optimize("-funroll-all-loops,-fpeel-loops,-funswitch-loops")*/ #include<bits/stdc++.h> using namespace std; //#define int long long #define endl "\n" #define all(v) v.begin(),v.end() #define gen(arr,n,nxt) generate(arr,arr+n,nxt) #define Blobo2_el_7akim_elly_3ayz_yro7_IOI_w_3ayz_yakol_jilaty ios_base::sync_with_stdio(false);cin.tie(0); const int mo=1e9+7,INF=1e18; int nxt(){int x;cin>>x;return x;} signed main(){ Blobo2_el_7akim_elly_3ayz_yro7_IOI_w_3ayz_yakol_jilaty int n=nxt(),k=nxt(),r=nxt(); int arr[n]; gen(arr,n,nxt); int freq[k]; memset(freq,0,sizeof freq); for(int i=0;i<r;i++){ int x = nxt(),c = nxt(); freq[x]=c; } int now[k]; memset(now,0,sizeof now); for(int i=0;i<n;i++)now[arr[i]]++; bool ok=0; for(int i=0;i<k;i++){ if(now[i]<freq[i]) ok=1; } if(ok){ cout<<"impossible"; return 0; } int l=0,mn=1e9; memset(now,0,sizeof now); int cnt=0; for(int i=0;i<k;i++)if(now[i]>=freq[i])cnt++; for(int i=0;i<n;i++){ now[arr[i]]++; if(now[arr[i]]==freq[arr[i]])cnt++; while(cnt==k){ if(now[arr[l]]==freq[arr[l]])break; now[arr[l]]--; l++; } if(cnt==k) mn=min(mn,i-l); } cout<<mn+1; return 0; }

Compilation message (stderr)

dna.cpp:19:24: warning: overflow in conversion from 'double' to 'int' changes value from '1.0e+18' to '2147483647' [-Woverflow]
   19 | const int mo=1e9+7,INF=1e18;
      |                        ^~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...