# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
927198 |
2024-02-14T12:00:19 Z |
vjudge1 |
Martian DNA (BOI18_dna) |
C++17 |
|
24 ms |
5108 KB |
// #pragma GCC target ("avx2")
// #pragma GCC optimization ("O3")
// #pragma GCC optimization ("unroll-loops")
#include <bits/stdc++.h>
#define int long long
#define ff first
#define ss second
#define pb push_back
#define yes cout<<"Yes\n"
#define no cout<<"No\n"
#define no1 cout<<"-1\n"
using namespace std;
const int N = 2e5+100;
const int M = 1e5+10;
const int INF = 1e18;
const int mod = 1e9+7;
// int binpow (int a, int n) {
// if (n == 0)
// return 1;
// if (n % 2 == 1)
// return (binpow (a, n-1) * a)%mod;
// else {
// int b = binpow (a, n/2);
// return (b * b)%mod;
// }
// }
int n,k,R;
int a[N];
int b[N];
int cnt[N];
void solve(){
cin>>n>>k>>R;
for(int i = 1;i<=n;i++){
cin>>a[i];
}
for(int i = 1;i<=R;i++){
int x,q;
cin>>x>>q;
b[x] = q;
}
int c = 0;
int l = 1;
int ans = INF;
for(int r = 1;r<=n;r++){
cnt[a[r]]++;
if(cnt[a[r]] == b[a[r]] && b[a[r]] != 0) c++;
while(l<r && cnt[a[l]]-1 >= b[a[l]]){
cnt[a[l]]--;
l++;
}
if(c == R) ans = min(ans,r-l+1);
}
if(ans == INF) cout<<"impossible\n";
else cout<<ans<<'\n';
}
signed main(){
ios_base::sync_with_stdio(0);
cin.tie(nullptr);
// cout.tie(nullptr);
int t = 1;
// cin>>t;
// cout<<"";
for(int i = 1;i<=t;i++){
// cout<<"Case "<<i<<": ";
solve();
// cout<<'\n';
}
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
4444 KB |
Output is correct |
2 |
Correct |
1 ms |
4444 KB |
Output is correct |
3 |
Correct |
1 ms |
4444 KB |
Output is correct |
4 |
Correct |
1 ms |
4444 KB |
Output is correct |
5 |
Correct |
1 ms |
4444 KB |
Output is correct |
6 |
Correct |
1 ms |
4444 KB |
Output is correct |
7 |
Correct |
1 ms |
4440 KB |
Output is correct |
8 |
Correct |
1 ms |
4444 KB |
Output is correct |
9 |
Correct |
1 ms |
4444 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
4444 KB |
Output is correct |
2 |
Correct |
1 ms |
4444 KB |
Output is correct |
3 |
Correct |
1 ms |
4444 KB |
Output is correct |
4 |
Correct |
1 ms |
4444 KB |
Output is correct |
5 |
Correct |
1 ms |
4444 KB |
Output is correct |
6 |
Correct |
1 ms |
4440 KB |
Output is correct |
7 |
Correct |
1 ms |
4444 KB |
Output is correct |
8 |
Correct |
1 ms |
4440 KB |
Output is correct |
9 |
Correct |
1 ms |
4444 KB |
Output is correct |
10 |
Correct |
1 ms |
4440 KB |
Output is correct |
11 |
Correct |
1 ms |
4444 KB |
Output is correct |
12 |
Correct |
1 ms |
4444 KB |
Output is correct |
13 |
Correct |
1 ms |
4444 KB |
Output is correct |
14 |
Correct |
1 ms |
4444 KB |
Output is correct |
15 |
Correct |
1 ms |
4440 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
12 ms |
4956 KB |
Output is correct |
2 |
Correct |
10 ms |
4956 KB |
Output is correct |
3 |
Correct |
10 ms |
4956 KB |
Output is correct |
4 |
Correct |
9 ms |
4820 KB |
Output is correct |
5 |
Correct |
12 ms |
4956 KB |
Output is correct |
6 |
Correct |
8 ms |
4956 KB |
Output is correct |
7 |
Correct |
11 ms |
4956 KB |
Output is correct |
8 |
Correct |
14 ms |
4956 KB |
Output is correct |
9 |
Correct |
12 ms |
5108 KB |
Output is correct |
10 |
Correct |
9 ms |
4820 KB |
Output is correct |
11 |
Correct |
1 ms |
4444 KB |
Output is correct |
12 |
Correct |
1 ms |
4444 KB |
Output is correct |
13 |
Correct |
1 ms |
4444 KB |
Output is correct |
14 |
Correct |
1 ms |
4444 KB |
Output is correct |
15 |
Correct |
1 ms |
4444 KB |
Output is correct |
16 |
Correct |
1 ms |
4440 KB |
Output is correct |
17 |
Correct |
1 ms |
4444 KB |
Output is correct |
18 |
Correct |
1 ms |
4444 KB |
Output is correct |
19 |
Correct |
1 ms |
4444 KB |
Output is correct |
20 |
Correct |
1 ms |
4444 KB |
Output is correct |
21 |
Correct |
1 ms |
4444 KB |
Output is correct |
22 |
Correct |
1 ms |
4444 KB |
Output is correct |
23 |
Correct |
1 ms |
4440 KB |
Output is correct |
24 |
Correct |
1 ms |
4440 KB |
Output is correct |
25 |
Correct |
1 ms |
4440 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
20 ms |
4956 KB |
Output is correct |
2 |
Correct |
18 ms |
4956 KB |
Output is correct |
3 |
Correct |
16 ms |
4956 KB |
Output is correct |
4 |
Correct |
9 ms |
4956 KB |
Output is correct |
5 |
Correct |
22 ms |
4952 KB |
Output is correct |
6 |
Correct |
24 ms |
5064 KB |
Output is correct |
7 |
Correct |
12 ms |
4956 KB |
Output is correct |
8 |
Correct |
15 ms |
4956 KB |
Output is correct |
9 |
Correct |
10 ms |
4956 KB |
Output is correct |
10 |
Correct |
12 ms |
4824 KB |
Output is correct |
11 |
Correct |
10 ms |
4956 KB |
Output is correct |
12 |
Correct |
9 ms |
4956 KB |
Output is correct |
13 |
Correct |
12 ms |
4956 KB |
Output is correct |
14 |
Correct |
9 ms |
4956 KB |
Output is correct |
15 |
Correct |
9 ms |
4956 KB |
Output is correct |
16 |
Correct |
14 ms |
4952 KB |
Output is correct |
17 |
Correct |
11 ms |
4956 KB |
Output is correct |
18 |
Correct |
9 ms |
4952 KB |
Output is correct |
19 |
Correct |
1 ms |
4440 KB |
Output is correct |
20 |
Correct |
1 ms |
4444 KB |
Output is correct |
21 |
Correct |
2 ms |
4444 KB |
Output is correct |
22 |
Correct |
1 ms |
4444 KB |
Output is correct |
23 |
Correct |
1 ms |
4444 KB |
Output is correct |
24 |
Correct |
1 ms |
4444 KB |
Output is correct |
25 |
Correct |
1 ms |
4444 KB |
Output is correct |
26 |
Correct |
1 ms |
4444 KB |
Output is correct |
27 |
Correct |
1 ms |
4444 KB |
Output is correct |
28 |
Correct |
1 ms |
4444 KB |
Output is correct |
29 |
Correct |
1 ms |
4444 KB |
Output is correct |
30 |
Correct |
1 ms |
4440 KB |
Output is correct |
31 |
Correct |
1 ms |
4444 KB |
Output is correct |
32 |
Correct |
1 ms |
4444 KB |
Output is correct |
33 |
Correct |
1 ms |
4444 KB |
Output is correct |