답안 #890934

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
890934 2023-12-22T05:21:39 Z LCJLY Martian DNA (BOI18_dna) C++14
100 / 100
30 ms 5116 KB
#include <bits/stdc++.h>
using namespace std;

#define int long long
#define ld long double
#define show(x,y) cout << y << " " << #x << endl;
#define show2(x,y,i,j) cout << y << " " << #x << "  " << j << " " << #i << endl;
#define show3(x,y,i,j,p,q) cout << y << " " << #x << "  " << j << " " << #i << "  " << q << " " << #p << endl; 
#define show4(x,y) for(auto it:x) cout << it << " "; cout << #y << endl;
typedef pair<int,int>pii;
typedef pair<pii,int>pi2;

void solve(){		
	int n,k,r;
	cin >> n >> k >> r;
	
	int arr[n];
	for(int x=0;x<n;x++){
		cin >> arr[x];
	}
	
	int need[n];
	memset(need,-1,sizeof(need));
	int temp,temp2;
	for(int x=0;x<r;x++){
		cin >> temp >> temp2;
		need[temp]=temp2;
	}
	
	int l=0;
	
	int done=0;
	int cnt[n];
	memset(cnt,0,sizeof(cnt));
	int best=LONG_LONG_MAX;
	for(int x=0;x<n;x++){
		//include x
		int val=arr[x];
		cnt[val]++;
		if(cnt[val]==need[val]) done++;
		
		while(done==r){
			best=min(best,x-l+1);
			int cur=arr[l];
			if(cnt[cur]==need[cur]) done--;
			cnt[cur]--;
			l++;
		}
	}
	
	
	if(best==LONG_LONG_MAX){
		cout << "impossible\n";
	}
	else cout << best;
	
	
}	

int32_t main(){										
	ios::sync_with_stdio(0);	
	cin.tie(0);
	int t=1;
	//cin >> t;
	while(t--){
		solve();
	}
}






# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 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 1 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 344 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 1 ms 348 KB Output is correct
9 Correct 0 ms 600 KB Output is correct
10 Correct 1 ms 348 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 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 10 ms 4956 KB Output is correct
2 Correct 11 ms 5084 KB Output is correct
3 Correct 11 ms 4956 KB Output is correct
4 Correct 10 ms 4956 KB Output is correct
5 Correct 15 ms 5088 KB Output is correct
6 Correct 11 ms 4956 KB Output is correct
7 Correct 12 ms 4924 KB Output is correct
8 Correct 19 ms 5072 KB Output is correct
9 Correct 14 ms 5088 KB Output is correct
10 Correct 11 ms 5068 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 1 ms 348 KB Output is correct
13 Correct 1 ms 348 KB Output is correct
14 Correct 1 ms 348 KB Output is correct
15 Correct 1 ms 348 KB Output is correct
16 Correct 1 ms 348 KB Output is correct
17 Correct 0 ms 348 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 0 ms 348 KB Output is correct
21 Correct 0 ms 348 KB Output is correct
22 Correct 0 ms 348 KB Output is correct
23 Correct 0 ms 348 KB Output is correct
24 Correct 0 ms 344 KB Output is correct
25 Correct 1 ms 348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 22 ms 4952 KB Output is correct
2 Correct 30 ms 5104 KB Output is correct
3 Correct 16 ms 4956 KB Output is correct
4 Correct 10 ms 4956 KB Output is correct
5 Correct 24 ms 5116 KB Output is correct
6 Correct 26 ms 4956 KB Output is correct
7 Correct 14 ms 5084 KB Output is correct
8 Correct 16 ms 4956 KB Output is correct
9 Correct 11 ms 4956 KB Output is correct
10 Correct 10 ms 4956 KB Output is correct
11 Correct 11 ms 4956 KB Output is correct
12 Correct 10 ms 5088 KB Output is correct
13 Correct 14 ms 4956 KB Output is correct
14 Correct 10 ms 5088 KB Output is correct
15 Correct 11 ms 5060 KB Output is correct
16 Correct 15 ms 5084 KB Output is correct
17 Correct 13 ms 4956 KB Output is correct
18 Correct 12 ms 5092 KB Output is correct
19 Correct 1 ms 348 KB Output is correct
20 Correct 0 ms 348 KB Output is correct
21 Correct 1 ms 348 KB Output is correct
22 Correct 1 ms 348 KB Output is correct
23 Correct 0 ms 348 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 0 ms 348 KB Output is correct
30 Correct 0 ms 452 KB Output is correct
31 Correct 0 ms 348 KB Output is correct
32 Correct 0 ms 348 KB Output is correct
33 Correct 0 ms 348 KB Output is correct