답안 #526285

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
526285 2022-02-14T07:47:51 Z bebecanvas Martian DNA (BOI18_dna) C++14
0 / 100
35 ms 6036 KB
#include <bits/stdc++.h>

using namespace std;
#define int long long
#define endl '\n'
#define sz(x) (int) (x).size()

signed main(){
 
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    
	int n, k, r; cin >> n >> k >> r;
	int v[200005];
	int arr[200005];
	for(int i=0; i<n; i++){cin >> arr[i];}
	for(int i=0; i<=k; i++){v[i]= 1;}
	for(int i=0; i<r; i++){
		int a, b; cin >> a >> b;
		v[a]= b;
	}
	
	int s= k;
	int e= n;
	bool yeaa= false;
	while(s<e){
		int mid= s+ (e-s)/2;
		int c[200005]={0};
		int count= 0;
		for(int i=0; i<mid; i++){
			c[arr[i]]++;
			if(c[arr[i]]==v[arr[i]]){count++;}
		}
		bool yea= false;
		if(count==k){yea= true;}
		for(int i=0; i<n- mid; i++){
			if(count==k){yea= true; yeaa= true; break;}
			c[arr[i]]--; 
			if(c[arr[i]]==v[arr[i]]-1){count--;}
			c[arr[i+mid]]++; 
			if(c[arr[i+mid]]==v[arr[i+mid]]){count++;}
		}
		if(count==k){yea= true; yeaa= true;}
		if(yea){e= mid;}
		else{s= mid+1;}
	}
	
	if(yeaa){cout << e << endl;}
	else{cout << "impossible" << endl;}
	
	
}

# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 4940 KB Output is correct
2 Incorrect 3 ms 5004 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 4940 KB Output is correct
2 Correct 5 ms 4940 KB Output is correct
3 Incorrect 5 ms 5012 KB Output isn't correct
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 32 ms 4980 KB Output is correct
2 Correct 24 ms 4940 KB Output is correct
3 Correct 20 ms 5384 KB Output is correct
4 Correct 23 ms 5372 KB Output is correct
5 Incorrect 30 ms 6036 KB Output isn't correct
6 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 35 ms 4996 KB Output isn't correct
2 Halted 0 ms 0 KB -