#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#pragma GCC target("popcnt")
using namespace std;
using namespace __gnu_pbds;
#define ll long long
#define pb push_back
#define emb emplace_back
#define emc emplace
#define pii pair<int,int>
#define pll pair<ll,ll>
#define F first
#define S second
template <class type_key, class type_val>
using um = unordered_map<type_key, type_val>;
template <class T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
template <class T>
using ordered_multiset = tree<T, null_type, less_equal<T>, rb_tree_tag, tree_order_statistics_node_update>;
int pref[200001][11];
signed main(void)
{
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int n, k, R;
cin >> n >> k >> R;
int a[n+1];
for( int i = 1; i <= n; i++ ) {
cin >> a[i];
}
pii Q[R+1];
for( int i = 1; i <= R; i++ ) {
cin >> Q[i].F >> Q[i].S;
}
for( int i = 1; i <= n; i++ ) {
for( int j = 1; j <= R; j++ ) {
pref[i][j] = pref[i-1][j] + (a[i] == Q[j].F);
}
}
for( int i = 1; i <= R; i++ ) {
if( pref[n][i] < Q[i].S ) {
cout << "impossible";
return 0;
}
}
int ans = INT_MAX;
for( int r = 1; r <= n; r++ ) {
bool ok = 1;
for( int l = 1; l <= r; l++ ) {
for( int i = 1; i <= R; i++ ) {
if( pref[r][i] - pref[l-1][i] < Q[i].S ) {
ok = 0;
break;
}
}
if( !ok ) break;
ans = min(ans, r-l+1);
}
}
cout << ans;
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
344 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
0 ms |
348 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
8 ms |
604 KB |
Output is correct |
2 |
Correct |
8 ms |
604 KB |
Output is correct |
3 |
Correct |
6 ms |
604 KB |
Output is correct |
4 |
Correct |
2 ms |
604 KB |
Output is correct |
5 |
Correct |
17 ms |
652 KB |
Output is correct |
6 |
Correct |
36 ms |
628 KB |
Output is correct |
7 |
Correct |
0 ms |
600 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
1 ms |
600 KB |
Output is correct |
10 |
Correct |
0 ms |
344 KB |
Output is correct |
11 |
Correct |
0 ms |
344 KB |
Output is correct |
12 |
Correct |
0 ms |
348 KB |
Output is correct |
13 |
Correct |
0 ms |
348 KB |
Output is correct |
14 |
Correct |
1 ms |
348 KB |
Output is correct |
15 |
Correct |
1 ms |
348 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
2027 ms |
9816 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
2050 ms |
3920 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |