/*
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
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 time |
Memory |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
1 ms |
204 KB |
Output is correct |
3 |
Correct |
0 ms |
204 KB |
Output is correct |
4 |
Correct |
1 ms |
204 KB |
Output is correct |
5 |
Correct |
1 ms |
204 KB |
Output is correct |
6 |
Correct |
1 ms |
204 KB |
Output is correct |
7 |
Correct |
0 ms |
204 KB |
Output is correct |
8 |
Correct |
0 ms |
204 KB |
Output is correct |
9 |
Correct |
1 ms |
204 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
332 KB |
Output is correct |
2 |
Correct |
1 ms |
332 KB |
Output is correct |
3 |
Correct |
1 ms |
332 KB |
Output is correct |
4 |
Correct |
1 ms |
320 KB |
Output is correct |
5 |
Correct |
1 ms |
332 KB |
Output is correct |
6 |
Correct |
1 ms |
332 KB |
Output is correct |
7 |
Correct |
1 ms |
204 KB |
Output is correct |
8 |
Correct |
0 ms |
204 KB |
Output is correct |
9 |
Correct |
0 ms |
204 KB |
Output is correct |
10 |
Correct |
0 ms |
204 KB |
Output is correct |
11 |
Correct |
0 ms |
204 KB |
Output is correct |
12 |
Correct |
1 ms |
204 KB |
Output is correct |
13 |
Correct |
1 ms |
260 KB |
Output is correct |
14 |
Correct |
1 ms |
204 KB |
Output is correct |
15 |
Correct |
1 ms |
308 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
17 ms |
1484 KB |
Output is correct |
2 |
Correct |
17 ms |
1484 KB |
Output is correct |
3 |
Correct |
20 ms |
1520 KB |
Output is correct |
4 |
Correct |
17 ms |
1460 KB |
Output is correct |
5 |
Correct |
22 ms |
2868 KB |
Output is correct |
6 |
Correct |
16 ms |
1356 KB |
Output is correct |
7 |
Correct |
17 ms |
1580 KB |
Output is correct |
8 |
Correct |
25 ms |
3900 KB |
Output is correct |
9 |
Correct |
24 ms |
1996 KB |
Output is correct |
10 |
Correct |
18 ms |
1480 KB |
Output is correct |
11 |
Correct |
1 ms |
332 KB |
Output is correct |
12 |
Correct |
1 ms |
332 KB |
Output is correct |
13 |
Correct |
1 ms |
332 KB |
Output is correct |
14 |
Correct |
1 ms |
332 KB |
Output is correct |
15 |
Correct |
1 ms |
332 KB |
Output is correct |
16 |
Correct |
1 ms |
332 KB |
Output is correct |
17 |
Correct |
0 ms |
204 KB |
Output is correct |
18 |
Correct |
1 ms |
308 KB |
Output is correct |
19 |
Correct |
0 ms |
204 KB |
Output is correct |
20 |
Correct |
1 ms |
204 KB |
Output is correct |
21 |
Correct |
0 ms |
204 KB |
Output is correct |
22 |
Correct |
0 ms |
204 KB |
Output is correct |
23 |
Correct |
0 ms |
204 KB |
Output is correct |
24 |
Correct |
0 ms |
204 KB |
Output is correct |
25 |
Correct |
1 ms |
204 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
37 ms |
3496 KB |
Output is correct |
2 |
Correct |
34 ms |
3120 KB |
Output is correct |
3 |
Correct |
27 ms |
2756 KB |
Output is correct |
4 |
Correct |
17 ms |
1480 KB |
Output is correct |
5 |
Correct |
41 ms |
4004 KB |
Output is correct |
6 |
Correct |
45 ms |
4468 KB |
Output is correct |
7 |
Correct |
22 ms |
2096 KB |
Output is correct |
8 |
Correct |
25 ms |
2356 KB |
Output is correct |
9 |
Correct |
17 ms |
1484 KB |
Output is correct |
10 |
Correct |
17 ms |
1456 KB |
Output is correct |
11 |
Correct |
18 ms |
1456 KB |
Output is correct |
12 |
Correct |
17 ms |
1484 KB |
Output is correct |
13 |
Correct |
24 ms |
2860 KB |
Output is correct |
14 |
Correct |
16 ms |
1480 KB |
Output is correct |
15 |
Correct |
17 ms |
1588 KB |
Output is correct |
16 |
Correct |
25 ms |
3916 KB |
Output is correct |
17 |
Correct |
22 ms |
2100 KB |
Output is correct |
18 |
Correct |
17 ms |
1480 KB |
Output is correct |
19 |
Correct |
1 ms |
204 KB |
Output is correct |
20 |
Correct |
1 ms |
332 KB |
Output is correct |
21 |
Correct |
1 ms |
320 KB |
Output is correct |
22 |
Correct |
1 ms |
332 KB |
Output is correct |
23 |
Correct |
1 ms |
332 KB |
Output is correct |
24 |
Correct |
1 ms |
204 KB |
Output is correct |
25 |
Correct |
1 ms |
204 KB |
Output is correct |
26 |
Correct |
1 ms |
204 KB |
Output is correct |
27 |
Correct |
1 ms |
204 KB |
Output is correct |
28 |
Correct |
0 ms |
204 KB |
Output is correct |
29 |
Correct |
0 ms |
204 KB |
Output is correct |
30 |
Correct |
0 ms |
312 KB |
Output is correct |
31 |
Correct |
0 ms |
204 KB |
Output is correct |
32 |
Correct |
0 ms |
204 KB |
Output is correct |
33 |
Correct |
1 ms |
204 KB |
Output is correct |