Submission #731671

# Submission time Handle Problem Language Result Execution time Memory
731671 2023-04-27T18:17:47 Z NintsiChkhaidze Martian DNA (BOI18_dna) C++17
100 / 100
31 ms 2664 KB
#include <bits/stdc++.h>
using namespace std;
 
const int N = 2e5 + 5,inf=1e9;
int a[N],mn[N],cnt[N];
 
signed main (){
	
	ios_base::sync_with_stdio(0),cin.tie(NULL),cout.tie(NULL);
	int n,k,R;
	cin>>n>>k>>R;
	
	for (int i = 1; i <= n; i++){
		cin>>a[i];
	}
	
	for (int i = 0; i < k; i++) mn[i] = inf;
	for (int i = 1; i <= R; i++){
		int x,y;
		cin>>x>>y;
		mn[x] = y;
	}
	
	int C = R,r = 0,ans=inf;
	for (int i = 1; i <= n; i++){
		while (C > 0 && r + 1 <= n){
			++r;
			cnt[a[r]]++;
			if (cnt[a[r]] - 1 < mn[a[r]] && cnt[a[r]] == mn[a[r]]) 
				C--;
		}
		if (C == 0) ans=min(ans,r - i + 1);
		
		cnt[a[i]]--;
		if (cnt[a[i]] + 1 == mn[a[i]] && cnt[a[i]] < mn[a[i]]) ++C;
	}
	if(ans==inf) cout<<"impossible";
	else cout<<ans;
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 0 ms 340 KB Output is correct
9 Correct 0 ms 340 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 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 1 ms 340 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 0 ms 212 KB Output is correct
12 Correct 0 ms 212 KB Output is correct
13 Correct 0 ms 212 KB Output is correct
14 Correct 0 ms 212 KB Output is correct
15 Correct 0 ms 212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 10 ms 1108 KB Output is correct
2 Correct 18 ms 1072 KB Output is correct
3 Correct 17 ms 1004 KB Output is correct
4 Correct 13 ms 1108 KB Output is correct
5 Correct 18 ms 1728 KB Output is correct
6 Correct 12 ms 1108 KB Output is correct
7 Correct 20 ms 1112 KB Output is correct
8 Correct 19 ms 2644 KB Output is correct
9 Correct 14 ms 1120 KB Output is correct
10 Correct 12 ms 1108 KB Output is correct
11 Correct 1 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
16 Correct 1 ms 340 KB Output is correct
17 Correct 0 ms 212 KB Output is correct
18 Correct 0 ms 212 KB Output is correct
19 Correct 0 ms 212 KB Output is correct
20 Correct 0 ms 340 KB Output is correct
21 Correct 0 ms 212 KB Output is correct
22 Correct 0 ms 212 KB Output is correct
23 Correct 0 ms 212 KB Output is correct
24 Correct 1 ms 212 KB Output is correct
25 Correct 0 ms 212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 30 ms 1612 KB Output is correct
2 Correct 31 ms 1492 KB Output is correct
3 Correct 19 ms 1476 KB Output is correct
4 Correct 10 ms 1108 KB Output is correct
5 Correct 30 ms 1860 KB Output is correct
6 Correct 30 ms 2448 KB Output is correct
7 Correct 15 ms 1108 KB Output is correct
8 Correct 17 ms 1192 KB Output is correct
9 Correct 11 ms 1116 KB Output is correct
10 Correct 13 ms 1108 KB Output is correct
11 Correct 13 ms 1108 KB Output is correct
12 Correct 13 ms 1108 KB Output is correct
13 Correct 17 ms 1652 KB Output is correct
14 Correct 10 ms 1108 KB Output is correct
15 Correct 12 ms 1100 KB Output is correct
16 Correct 18 ms 2664 KB Output is correct
17 Correct 16 ms 1080 KB Output is correct
18 Correct 12 ms 1108 KB Output is correct
19 Correct 1 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 1 ms 340 KB Output is correct
23 Correct 1 ms 340 KB Output is correct
24 Correct 1 ms 340 KB Output is correct
25 Correct 1 ms 212 KB Output is correct
26 Correct 1 ms 212 KB Output is correct
27 Correct 0 ms 212 KB Output is correct
28 Correct 0 ms 212 KB Output is correct
29 Correct 1 ms 212 KB Output is correct
30 Correct 0 ms 212 KB Output is correct
31 Correct 1 ms 212 KB Output is correct
32 Correct 0 ms 212 KB Output is correct
33 Correct 0 ms 212 KB Output is correct