#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
#define ll long long
#define ld long double
#define vl vector<ll>
#define vi vector<int>
#define pii pair<int, int>
#define pll pair<ll, ll>
#define all(v) v.begin(), v.end()
#define pb push_back
#define f first
#define s second
using namespace std;
using namespace __gnu_pbds;
typedef tree<ll, null_type, less<ll>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
const ll sz = 15;
map<ll, ll>mp[sz];
int main()
{
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
ll tests = 1;
//cin >> tests;
while(tests--)
{
ll n, k, r, i, j, ans = LLONG_MAX;
cin >> n >> k >> r;
ll a[n+5];
for(i = 1; i <= n; i++)
cin >> a[i];
map<ll, ll>q;
vl v;
for(i = 1; i <= r; i++)
{
ll x, y;
cin >> x >> y;
q[x] = y;
v.pb(x);
}
for(i = 1; i <= n; i++)
{
for(auto u : v){
mp[u][i] = mp[u][i-1];
if(u == a[i])
mp[u][i]++;
}
}
for(i = 1; i <= n; i++)
{
ll l = i, r = n;
while(l <= r)
{
ll mid = (l + r) / 2;
bool possible = true;
for(auto u : v)
{
ll cnt = mp[u][mid] - mp[u][i-1];
if(cnt < q[u])
{
possible = false;
break;
}
}
if(!possible)
l = mid + 1;
else{
r = mid - 1;
ans = min(ans, mid - i + 1);
}
}
}
if(ans == LLONG_MAX)
cout << "impossible\n";
else
cout << ans << "\n";
}
}
Compilation message
dna.cpp: In function 'int main()':
dna.cpp:28:24: warning: unused variable 'j' [-Wunused-variable]
28 | ll n, k, r, i, j, ans = LLONG_MAX;
| ^
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Runtime error |
0 ms |
348 KB |
Execution killed with signal 11 |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
6 ms |
600 KB |
Output is correct |
2 |
Correct |
19 ms |
2908 KB |
Output is correct |
3 |
Runtime error |
1 ms |
604 KB |
Execution killed with signal 11 |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
2013 ms |
114548 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
44 ms |
15056 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |