# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
1009832 |
2024-06-28T06:27:23 Z |
kebine |
Martian DNA (BOI18_dna) |
C++17 |
|
677 ms |
36996 KB |
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
#define int long long
#define inf LLONG_MAX
#define pb push_back
#define lc 2*pos+1
#define rc 2*pos+2
#define halleluya ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
signed main(){
halleluya
int n,k,re;cin>>n>>k>>re;
int num[n];
map<int,int>req;
map<int,int>freq;
int tot=re;
map<int,int>ad;
for (int i=0;i<n;i++)cin>>num[i];
while (re--){
int x,y;cin>>x>>y;
ad[x]=1;
req[x]=y;
}
// for (int i=0;i<n;i++){
// for (auto x:jum) {
// if (0<i) freq[{i,x}]=freq[{i-1,x}];
// if (x==num[i]) freq[{i,x}]++;
// }
// }
int l=0,r=-1;
map<int,bool>vis;
int ben=0;
int ans=inf;
while(l<n){
while (ben<tot && r+1<n){
r++;
freq[num[r]]++;
// cout<<r<<" "<<num[r]<<" "<<freq[num[r]]<<" "<<req[num[r]] <<endl;
if (ad[num[r]]){
if (freq[num[r]]>=req[num[r]] && vis[num[r]]==0 ){
vis[num[r]]=1;
// cout<<"namben "<<num[r]<<" di "<<r<<endl;
ben++;
}
}
}
// cout<<l<<" "<<r<<endl;
if (ben>=tot) ans=min(ans,r-l+1);
freq[num[l]]--;
if (ad[num[l]]){
if (freq[num[l]]<req[num[l]] && vis[num[l]]){
vis[num[l]]=0;
ben--;
}
// cout<<ben<<endl;
}
l++;
}
if (ans==inf)cout<<"impossible";
else cout<<ans;
}
// impossible -> jumlah kurang atau emang gaada substringnya
// harus consecutive
// constraint r
// cuman perlu shortest
// sliding window?
// cuma save jumlah k
// n*k
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
1 ms |
344 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
344 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
0 ms |
348 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
2 ms |
604 KB |
Output is correct |
4 |
Correct |
2 ms |
860 KB |
Output is correct |
5 |
Correct |
2 ms |
600 KB |
Output is correct |
6 |
Correct |
1 ms |
348 KB |
Output is correct |
7 |
Correct |
1 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
1 ms |
348 KB |
Output is correct |
10 |
Correct |
0 ms |
344 KB |
Output is correct |
11 |
Correct |
1 ms |
348 KB |
Output is correct |
12 |
Correct |
0 ms |
348 KB |
Output is correct |
13 |
Correct |
0 ms |
348 KB |
Output is correct |
14 |
Correct |
0 ms |
344 KB |
Output is correct |
15 |
Correct |
1 ms |
348 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
14 ms |
1880 KB |
Output is correct |
2 |
Correct |
11 ms |
1884 KB |
Output is correct |
3 |
Correct |
33 ms |
2012 KB |
Output is correct |
4 |
Correct |
15 ms |
1884 KB |
Output is correct |
5 |
Correct |
148 ms |
11860 KB |
Output is correct |
6 |
Correct |
21 ms |
1884 KB |
Output is correct |
7 |
Correct |
35 ms |
1880 KB |
Output is correct |
8 |
Correct |
242 ms |
26804 KB |
Output is correct |
9 |
Correct |
86 ms |
2788 KB |
Output is correct |
10 |
Correct |
18 ms |
1880 KB |
Output is correct |
11 |
Correct |
1 ms |
348 KB |
Output is correct |
12 |
Correct |
1 ms |
348 KB |
Output is correct |
13 |
Correct |
2 ms |
604 KB |
Output is correct |
14 |
Correct |
2 ms |
860 KB |
Output is correct |
15 |
Correct |
2 ms |
604 KB |
Output is correct |
16 |
Correct |
1 ms |
344 KB |
Output is correct |
17 |
Correct |
0 ms |
348 KB |
Output is correct |
18 |
Correct |
1 ms |
348 KB |
Output is correct |
19 |
Correct |
0 ms |
348 KB |
Output is correct |
20 |
Correct |
0 ms |
344 KB |
Output is correct |
21 |
Correct |
0 ms |
348 KB |
Output is correct |
22 |
Correct |
0 ms |
348 KB |
Output is correct |
23 |
Correct |
1 ms |
344 KB |
Output is correct |
24 |
Correct |
0 ms |
348 KB |
Output is correct |
25 |
Correct |
0 ms |
348 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
470 ms |
22036 KB |
Output is correct |
2 |
Correct |
388 ms |
16816 KB |
Output is correct |
3 |
Correct |
273 ms |
12012 KB |
Output is correct |
4 |
Correct |
12 ms |
2020 KB |
Output is correct |
5 |
Correct |
531 ms |
24420 KB |
Output is correct |
6 |
Correct |
677 ms |
36996 KB |
Output is correct |
7 |
Correct |
201 ms |
3924 KB |
Output is correct |
8 |
Correct |
224 ms |
6228 KB |
Output is correct |
9 |
Correct |
14 ms |
2020 KB |
Output is correct |
10 |
Correct |
10 ms |
1884 KB |
Output is correct |
11 |
Correct |
14 ms |
2020 KB |
Output is correct |
12 |
Correct |
15 ms |
2020 KB |
Output is correct |
13 |
Correct |
163 ms |
12016 KB |
Output is correct |
14 |
Correct |
25 ms |
2016 KB |
Output is correct |
15 |
Correct |
26 ms |
2016 KB |
Output is correct |
16 |
Correct |
247 ms |
26924 KB |
Output is correct |
17 |
Correct |
91 ms |
2908 KB |
Output is correct |
18 |
Correct |
19 ms |
2020 KB |
Output is correct |
19 |
Correct |
1 ms |
348 KB |
Output is correct |
20 |
Correct |
1 ms |
348 KB |
Output is correct |
21 |
Correct |
2 ms |
604 KB |
Output is correct |
22 |
Correct |
2 ms |
860 KB |
Output is correct |
23 |
Correct |
2 ms |
604 KB |
Output is correct |
24 |
Correct |
1 ms |
348 KB |
Output is correct |
25 |
Correct |
0 ms |
348 KB |
Output is correct |
26 |
Correct |
0 ms |
348 KB |
Output is correct |
27 |
Correct |
0 ms |
348 KB |
Output is correct |
28 |
Correct |
0 ms |
348 KB |
Output is correct |
29 |
Correct |
1 ms |
348 KB |
Output is correct |
30 |
Correct |
0 ms |
348 KB |
Output is correct |
31 |
Correct |
0 ms |
348 KB |
Output is correct |
32 |
Correct |
1 ms |
348 KB |
Output is correct |
33 |
Correct |
1 ms |
348 KB |
Output is correct |