#include <bits/stdc++.h>
using namespace std;
const int nx=2e5+5;
int n, v[nx], k, r, res[nx], b, q, ans=INT_MAX;
int main()
{
cin.tie(NULL)->sync_with_stdio(false);
cin>>n>>k>>r;
for (int i=1; i<=n; i++) cin>>v[i], res[i]=INT_MAX;
for (int i=1; i<=r; i++)
{
cin>>b>>q;
deque<int> dq;
for (int j=1; j<=n; j++)
{
if (v[j]==b) dq.push_back(j);
while (!dq.empty()&&dq.size()>q) dq.pop_front();
if (dq.size()>=q) res[j]=min(res[j], dq.front());
else res[j]=-1;
//cout<<i<<' '<<j<<' '<<res[j]<<'\n';
}
}
for (int i=1; i<=n; i++) ans=min(ans, res[i]!=-1?i-res[i]+1:INT_MAX);
if (ans==INT_MAX) cout<<"impossible";
else cout<<ans;
}
Compilation message
dna.cpp: In function 'int main()':
dna.cpp:20:42: warning: comparison of integer expressions of different signedness: 'std::deque<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
20 | while (!dq.empty()&&dq.size()>q) dq.pop_front();
| ~~~~~~~~~^~
dna.cpp:21:26: warning: comparison of integer expressions of different signedness: 'std::deque<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
21 | if (dq.size()>=q) res[j]=min(res[j], dq.front());
| ~~~~~~~~~^~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
344 KB |
Output is correct |
2 |
Correct |
1 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
1 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
1 ms |
348 KB |
Output is correct |
7 |
Correct |
1 ms |
344 KB |
Output is correct |
8 |
Correct |
0 ms |
344 KB |
Output is correct |
9 |
Correct |
1 ms |
348 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Correct |
1 ms |
348 KB |
Output is correct |
3 |
Correct |
1 ms |
348 KB |
Output is correct |
4 |
Correct |
1 ms |
348 KB |
Output is correct |
5 |
Correct |
1 ms |
348 KB |
Output is correct |
6 |
Correct |
1 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
352 KB |
Output is correct |
8 |
Correct |
1 ms |
348 KB |
Output is correct |
9 |
Correct |
0 ms |
348 KB |
Output is correct |
10 |
Correct |
1 ms |
348 KB |
Output is correct |
11 |
Correct |
1 ms |
464 KB |
Output is correct |
12 |
Correct |
0 ms |
348 KB |
Output is correct |
13 |
Correct |
0 ms |
464 KB |
Output is correct |
14 |
Correct |
1 ms |
348 KB |
Output is correct |
15 |
Correct |
0 ms |
352 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
21 ms |
2392 KB |
Output is correct |
2 |
Correct |
11 ms |
2652 KB |
Output is correct |
3 |
Correct |
20 ms |
2452 KB |
Output is correct |
4 |
Correct |
16 ms |
2444 KB |
Output is correct |
5 |
Correct |
23 ms |
3164 KB |
Output is correct |
6 |
Correct |
16 ms |
2264 KB |
Output is correct |
7 |
Correct |
15 ms |
2396 KB |
Output is correct |
8 |
Correct |
25 ms |
3204 KB |
Output is correct |
9 |
Correct |
23 ms |
2904 KB |
Output is correct |
10 |
Correct |
17 ms |
2396 KB |
Output is correct |
11 |
Correct |
1 ms |
348 KB |
Output is correct |
12 |
Correct |
1 ms |
348 KB |
Output is correct |
13 |
Correct |
1 ms |
348 KB |
Output is correct |
14 |
Correct |
1 ms |
348 KB |
Output is correct |
15 |
Correct |
1 ms |
496 KB |
Output is correct |
16 |
Correct |
1 ms |
348 KB |
Output is correct |
17 |
Correct |
1 ms |
348 KB |
Output is correct |
18 |
Correct |
1 ms |
344 KB |
Output is correct |
19 |
Correct |
1 ms |
348 KB |
Output is correct |
20 |
Correct |
1 ms |
348 KB |
Output is correct |
21 |
Correct |
1 ms |
348 KB |
Output is correct |
22 |
Correct |
0 ms |
348 KB |
Output is correct |
23 |
Correct |
1 ms |
348 KB |
Output is correct |
24 |
Correct |
0 ms |
348 KB |
Output is correct |
25 |
Correct |
1 ms |
348 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
2028 ms |
3164 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |