/* Author : Mychecksdead */
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef long double ld;
#define MOD (1000000000+7)
#define MOD1 (998244353)
#define PI 3.1415926535
#define pb push_back
#define setp() cout << setprecision(15)
#define all(x) x.begin(), x.end()
#define debug(x) cerr << #x << " is " << x << '\n';
const int N = 1e6+100, M = 1e5+10, F = 2147483646, K = 20;
int n, k, s, a[N], dp[N][11], arr[N];
map<int, int> m;
void solve(){
cin >> n >> k >> s;
for(int i = 1; i <= n; ++i) cin >> a[i];
for(int i = 1; i <= s; ++i){
int c, x; cin >> c >> x;
arr[i] = x;
m[c] = i;
}
for(int i = 0; i <= n; ++i) for(int j = 0; j <= s; ++j) dp[i][j] = 0;
for(int i = 1; i <= n; ++i){
for(int j = 1; j <= s; ++j) dp[i][j] = dp[i - 1][j];
dp[i][m[a[i]]]++;
}
int best = MOD;
for(int i = 1; i <= n; ++i){
int l = 1, r = i, ans = -1;
while(l <= r){
int mid = (l + r) >> 1;
bool ok = 1;
for(int j = 1; j <= s; ++j) if(dp[i][j] - dp[mid - 1][j] < arr[j]) ok = 0;
if(ok){
ans = mid;
l = mid + 1;
}else r = mid - 1;
}
if(ans > -1) best = min(best, i - ans + 1);
}
if(best == MOD) cout << "impossible";
else cout << best;
}
int main(){
cin.tie(0); ios::sync_with_stdio(0);
int T = 1, aa;
// cin >> T;aa=T;
while(T--){
// cout << "Case #" << aa-T << ": ";
solve();
cout << '\n';
}
return 0;
}
Compilation message
dna.cpp: In function 'int main()':
dna.cpp:56:16: warning: unused variable 'aa' [-Wunused-variable]
56 | int T = 1, aa;
| ^~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
340 KB |
Output is correct |
2 |
Correct |
1 ms |
340 KB |
Output is correct |
3 |
Correct |
1 ms |
340 KB |
Output is correct |
4 |
Correct |
0 ms |
340 KB |
Output is correct |
5 |
Correct |
1 ms |
340 KB |
Output is correct |
6 |
Correct |
0 ms |
340 KB |
Output is correct |
7 |
Correct |
0 ms |
340 KB |
Output is correct |
8 |
Correct |
0 ms |
340 KB |
Output is correct |
9 |
Correct |
0 ms |
340 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
468 KB |
Output is correct |
2 |
Correct |
1 ms |
468 KB |
Output is correct |
3 |
Correct |
2 ms |
676 KB |
Output is correct |
4 |
Correct |
2 ms |
700 KB |
Output is correct |
5 |
Correct |
3 ms |
596 KB |
Output is correct |
6 |
Correct |
1 ms |
468 KB |
Output is correct |
7 |
Correct |
0 ms |
340 KB |
Output is correct |
8 |
Correct |
0 ms |
340 KB |
Output is correct |
9 |
Correct |
1 ms |
340 KB |
Output is correct |
10 |
Correct |
1 ms |
340 KB |
Output is correct |
11 |
Correct |
0 ms |
340 KB |
Output is correct |
12 |
Correct |
1 ms |
340 KB |
Output is correct |
13 |
Correct |
1 ms |
340 KB |
Output is correct |
14 |
Correct |
1 ms |
340 KB |
Output is correct |
15 |
Correct |
1 ms |
340 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
49 ms |
10068 KB |
Output is correct |
2 |
Correct |
25 ms |
10068 KB |
Output is correct |
3 |
Correct |
53 ms |
10156 KB |
Output is correct |
4 |
Correct |
51 ms |
10076 KB |
Output is correct |
5 |
Correct |
95 ms |
14628 KB |
Output is correct |
6 |
Correct |
48 ms |
10132 KB |
Output is correct |
7 |
Correct |
53 ms |
10312 KB |
Output is correct |
8 |
Correct |
130 ms |
20320 KB |
Output is correct |
9 |
Correct |
76 ms |
10956 KB |
Output is correct |
10 |
Correct |
53 ms |
10120 KB |
Output is correct |
11 |
Correct |
1 ms |
464 KB |
Output is correct |
12 |
Correct |
1 ms |
468 KB |
Output is correct |
13 |
Correct |
2 ms |
604 KB |
Output is correct |
14 |
Correct |
2 ms |
724 KB |
Output is correct |
15 |
Correct |
2 ms |
596 KB |
Output is correct |
16 |
Correct |
2 ms |
468 KB |
Output is correct |
17 |
Correct |
1 ms |
332 KB |
Output is correct |
18 |
Correct |
1 ms |
340 KB |
Output is correct |
19 |
Correct |
0 ms |
340 KB |
Output is correct |
20 |
Correct |
1 ms |
340 KB |
Output is correct |
21 |
Correct |
1 ms |
340 KB |
Output is correct |
22 |
Correct |
0 ms |
340 KB |
Output is correct |
23 |
Correct |
1 ms |
340 KB |
Output is correct |
24 |
Correct |
0 ms |
340 KB |
Output is correct |
25 |
Correct |
1 ms |
340 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
2078 ms |
15940 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |