답안 #824787

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
824787 2023-08-14T10:08:18 Z ThylOne Martian DNA (BOI18_dna) C++14
100 / 100
75 ms 4508 KB
#include<bits/stdc++.h>

using namespace std;

int main(){
	int N,K,R;cin>>N>>K>>R;
	vector<int> nums(N);
	int occ[K];
	int wantedOcc[K];
	for(int i = 0 ; i <K;i++)occ[i]=wantedOcc[i]=0;
	for(int i = 0 ; i <N;i++){cin>>nums[i];}
	
	
	for(int i=0;i<R;i++){
		int nuc,w;cin>>nuc>>w;
		wantedOcc[nuc]=w;
	}
	int ans = N+1;
	int left=0;
	int nbGood=0;
	for(int p=0;p<N;p++){
		int val=nums[p];
		if(wantedOcc[val]==0)continue;
		occ[val]++;
		if(occ[val]==wantedOcc[val]){
			nbGood++;
		}
		while(nbGood==R && left<N && (wantedOcc[nums[left]]==0 || occ[nums[left]]-1>=wantedOcc[nums[left]])){
			int val2 = nums[left];
			occ[nums[left]]--;
			left++;
			if(wantedOcc[val2]==0)continue;
		}
		
		
		if(nbGood==R){
			ans = min(ans,p-left+1);
		}
	}
	if(ans==N+1){
		cout<<"impossible"<<endl;
	}else{
		cout<<ans<<endl;
	}
	
	
	return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 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 212 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 212 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 336 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 1 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 1 ms 212 KB Output is correct
14 Correct 0 ms 212 KB Output is correct
15 Correct 1 ms 212 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 26 ms 1460 KB Output is correct
2 Correct 24 ms 1460 KB Output is correct
3 Correct 24 ms 1492 KB Output is correct
4 Correct 29 ms 1460 KB Output is correct
5 Correct 40 ms 2836 KB Output is correct
6 Correct 22 ms 1464 KB Output is correct
7 Correct 27 ms 1620 KB Output is correct
8 Correct 43 ms 3896 KB Output is correct
9 Correct 36 ms 2004 KB Output is correct
10 Correct 23 ms 1488 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Correct 1 ms 212 KB Output is correct
13 Correct 1 ms 340 KB Output is correct
14 Correct 1 ms 316 KB Output is correct
15 Correct 1 ms 340 KB Output is correct
16 Correct 1 ms 212 KB Output is correct
17 Correct 0 ms 212 KB Output is correct
18 Correct 1 ms 212 KB Output is correct
19 Correct 0 ms 212 KB Output is correct
20 Correct 0 ms 212 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 300 KB Output is correct
24 Correct 1 ms 300 KB Output is correct
25 Correct 0 ms 212 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 64 ms 3408 KB Output is correct
2 Correct 58 ms 3076 KB Output is correct
3 Correct 50 ms 2812 KB Output is correct
4 Correct 23 ms 1364 KB Output is correct
5 Correct 73 ms 4016 KB Output is correct
6 Correct 75 ms 4508 KB Output is correct
7 Correct 38 ms 2144 KB Output is correct
8 Correct 43 ms 2380 KB Output is correct
9 Correct 23 ms 1496 KB Output is correct
10 Correct 24 ms 1408 KB Output is correct
11 Correct 24 ms 1460 KB Output is correct
12 Correct 23 ms 1492 KB Output is correct
13 Correct 40 ms 2852 KB Output is correct
14 Correct 24 ms 1460 KB Output is correct
15 Correct 27 ms 1588 KB Output is correct
16 Correct 43 ms 3788 KB Output is correct
17 Correct 35 ms 2024 KB Output is correct
18 Correct 24 ms 1464 KB Output is correct
19 Correct 2 ms 212 KB Output is correct
20 Correct 1 ms 212 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 212 KB Output is correct
25 Correct 1 ms 212 KB Output is correct
26 Correct 0 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 0 ms 212 KB Output is correct
30 Correct 0 ms 296 KB Output is correct
31 Correct 0 ms 212 KB Output is correct
32 Correct 0 ms 304 KB Output is correct
33 Correct 0 ms 296 KB Output is correct