답안 #522693

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
522693 2022-02-05T12:38:13 Z bebecanvas Martian DNA (BOI18_dna) C++14
0 / 100
26 ms 6724 KB
#include <bits/stdc++.h>

using namespace std;
#define int long long
#define endl '\n'

signed main(){
	
	ios_base::sync_with_stdio(false);
    cin.tie(0);
    
    int n, k, r; cin >> n >> k >> r;
    int a[200005];
    for(int i=0; i<n; i++){cin >> a[i];}
	int b[200005]={0};
	int c[200005];
	for(int i=0; i<k; i++){c[i]=1;}
	for(int i=0; i<r; i++){
		int q, w; cin >> q >> w;
		c[q]= w;
	}
    
    int ans= -1;
    int count= 0;
    int s= 0; int e= 0;
    for(int i=0; i<n; i++){
		b[a[i]]++;
		if(b[a[i]]==c[a[i]]){count++;}
		if(count==k){e= i; ans= e-s+1; break;}
	}
    //cout << ans << endl;
    if(count==k){
		//cout << b[a[s]] << " " << c[a[s]] << endl;
		while(e!=n){
			//cout << e << endl;
			while(b[a[s]]>c[a[s]]){
				//cout << "lol" << endl;
				b[a[s]]--;
				s++;
				//cout << "s " << s << endl;
				ans= min(ans, e-s+1);
			}
			e++;
			b[a[e]]++;
			ans= min(ans, e-s+1);
		}
		cout << ans << endl;
	}else{
		cout << "impossible" << endl;
	}
}


# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 4940 KB Output is correct
2 Incorrect 2 ms 4940 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 4940 KB Output is correct
2 Correct 3 ms 4940 KB Output is correct
3 Incorrect 3 ms 5016 KB Output isn't correct
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 12 ms 5268 KB Output is correct
2 Correct 15 ms 5356 KB Output is correct
3 Correct 14 ms 5356 KB Output is correct
4 Correct 13 ms 5388 KB Output is correct
5 Incorrect 17 ms 6028 KB Output isn't correct
6 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 26 ms 6724 KB Output isn't correct
2 Halted 0 ms 0 KB -