//Sorry but iam targeting IOI :))
//NEVER LOSE HOPE
#pragma GCC optimize ("O3")
#pragma GCC optimize ("unroll-loops")
#include <bits/stdc++.h>
#define endl "\n"
#define ceil(a,b) (a+(b-1))/b
#define all(v) v.begin(),v.end()
#define int long long int
#define Hidden ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0);
using namespace std;
const int N=3e4+10,mod = 1e9+7;
int32_t main(){
int n,k,rr;
cin>>n>>k>>rr;
int arr[n];
map<int,int>mp,req,dif;
set<int>st;
for(int i = 0 ; i < n ; i ++)
{
cin>>arr[i];
}
int flg=0;
for(int i = 0 ; i < rr ; i ++)
{
int x,y;
cin>>x>>y;
req[x]=y;
}
int l=0,r=0,ans=INT_MAX,cnt=0;
while(l<=r)
{
while(r<n && cnt<req.size())
{
mp[arr[r]]++;
if(req.count(arr[r]) && mp[arr[r]]==req[arr[r]]) cnt++;
r++;
}
if(cnt==req.size()) ans=min(ans,r-l);
mp[arr[l]]--;
if(req.count(arr[l])&&req[arr[l]]>mp[arr[l]]) cnt--;
l++;
}
if(ans==INT_MAX)
{
cout<<"impossible"<<endl;
return 0;
}
cout<<ans<<endl;
}
Compilation message
dna.cpp: In function 'int32_t main()':
dna.cpp:33:21: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::map<long long int, long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
33 | while(r<n && cnt<req.size())
| ~~~^~~~~~~~~~~
dna.cpp:39:11: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::map<long long int, long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
39 | if(cnt==req.size()) ans=min(ans,r-l);
| ~~~^~~~~~~~~~~~
dna.cpp:23:7: warning: unused variable 'flg' [-Wunused-variable]
23 | int flg=0;
| ^~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
204 KB |
Output is correct |
2 |
Correct |
0 ms |
204 KB |
Output is correct |
3 |
Correct |
0 ms |
204 KB |
Output is correct |
4 |
Correct |
0 ms |
204 KB |
Output is correct |
5 |
Correct |
0 ms |
204 KB |
Output is correct |
6 |
Correct |
0 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 |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
2 ms |
204 KB |
Output is correct |
3 |
Correct |
3 ms |
460 KB |
Output is correct |
4 |
Correct |
3 ms |
460 KB |
Output is correct |
5 |
Correct |
3 ms |
332 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 |
0 ms |
204 KB |
Output is correct |
10 |
Correct |
0 ms |
204 KB |
Output is correct |
11 |
Correct |
1 ms |
204 KB |
Output is correct |
12 |
Correct |
0 ms |
204 KB |
Output is correct |
13 |
Correct |
0 ms |
204 KB |
Output is correct |
14 |
Correct |
1 ms |
204 KB |
Output is correct |
15 |
Correct |
1 ms |
204 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
44 ms |
1740 KB |
Output is correct |
2 |
Correct |
41 ms |
1740 KB |
Output is correct |
3 |
Correct |
46 ms |
1740 KB |
Output is correct |
4 |
Correct |
45 ms |
1840 KB |
Output is correct |
5 |
Correct |
163 ms |
6832 KB |
Output is correct |
6 |
Correct |
51 ms |
1844 KB |
Output is correct |
7 |
Correct |
63 ms |
1844 KB |
Output is correct |
8 |
Correct |
269 ms |
14356 KB |
Output is correct |
9 |
Correct |
117 ms |
2340 KB |
Output is correct |
10 |
Correct |
53 ms |
1828 KB |
Output is correct |
11 |
Correct |
1 ms |
204 KB |
Output is correct |
12 |
Correct |
1 ms |
204 KB |
Output is correct |
13 |
Correct |
3 ms |
460 KB |
Output is correct |
14 |
Correct |
3 ms |
460 KB |
Output is correct |
15 |
Correct |
3 ms |
332 KB |
Output is correct |
16 |
Correct |
2 ms |
204 KB |
Output is correct |
17 |
Correct |
0 ms |
204 KB |
Output is correct |
18 |
Correct |
0 ms |
204 KB |
Output is correct |
19 |
Correct |
0 ms |
204 KB |
Output is correct |
20 |
Correct |
1 ms |
204 KB |
Output is correct |
21 |
Correct |
1 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 |
1 ms |
204 KB |
Output is correct |
25 |
Correct |
0 ms |
204 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
528 ms |
11900 KB |
Output is correct |
2 |
Correct |
398 ms |
9472 KB |
Output is correct |
3 |
Correct |
278 ms |
6840 KB |
Output is correct |
4 |
Correct |
39 ms |
1740 KB |
Output is correct |
5 |
Correct |
537 ms |
13104 KB |
Output is correct |
6 |
Correct |
661 ms |
19364 KB |
Output is correct |
7 |
Correct |
256 ms |
2808 KB |
Output is correct |
8 |
Correct |
293 ms |
4020 KB |
Output is correct |
9 |
Correct |
44 ms |
1740 KB |
Output is correct |
10 |
Correct |
40 ms |
1848 KB |
Output is correct |
11 |
Correct |
47 ms |
1740 KB |
Output is correct |
12 |
Correct |
45 ms |
1740 KB |
Output is correct |
13 |
Correct |
161 ms |
6856 KB |
Output is correct |
14 |
Correct |
57 ms |
1740 KB |
Output is correct |
15 |
Correct |
63 ms |
1844 KB |
Output is correct |
16 |
Correct |
257 ms |
14356 KB |
Output is correct |
17 |
Correct |
121 ms |
2244 KB |
Output is correct |
18 |
Correct |
53 ms |
1836 KB |
Output is correct |
19 |
Correct |
1 ms |
204 KB |
Output is correct |
20 |
Correct |
1 ms |
204 KB |
Output is correct |
21 |
Correct |
3 ms |
460 KB |
Output is correct |
22 |
Correct |
3 ms |
460 KB |
Output is correct |
23 |
Correct |
3 ms |
332 KB |
Output is correct |
24 |
Correct |
1 ms |
204 KB |
Output is correct |
25 |
Correct |
0 ms |
204 KB |
Output is correct |
26 |
Correct |
0 ms |
204 KB |
Output is correct |
27 |
Correct |
0 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 |
1 ms |
204 KB |
Output is correct |
31 |
Correct |
1 ms |
204 KB |
Output is correct |
32 |
Correct |
0 ms |
204 KB |
Output is correct |
33 |
Correct |
1 ms |
204 KB |
Output is correct |