제출 #949115

#제출 시각아이디문제언어결과실행 시간메모리
949115koukirocks Martian DNA (BOI18_dna)C++17
100 / 100
27 ms4956 KiB
#include <bits/stdc++.h>
#define speed ios_base::sync_with_stdio(0); cin.tie(0)
#define all(x) (x).begin(),(x).end()
#define F first
#define S second
 
using namespace std;
typedef long long ll;
typedef double db;
typedef long double ldb;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
 
const ll MAX=2e5+10,P=998244353;
const ll INF=0x3f3f3f3f,oo=0x3f3f3f3f3f3f3f3f;

int n,k,r;
int dna[MAX];
int cnt[MAX];
int req[MAX];

int main() {
	speed;
	cin>>n>>k>>r;
	for (int i=1;i<=n;i++) {
		cin>>dna[i];
	}
	memset(cnt,0,sizeof(cnt));
	memset(req,0,sizeof(req));
	for (int i=0;i<r;i++) {
		int b,q;
		cin>>b>>q;
		req[b]=q;
	}
	int ttl=n-r;
	int ans=INF;
	int l=1;
	for (int r=1;r<=n;r++) {
		cnt[dna[r]]++;
		if (cnt[dna[r]]==req[dna[r]]) ttl++;
		if (ttl<n) continue;
		while (cnt[dna[l]]!=req[dna[l]]) {
			cnt[dna[l]]--;
			l++;
		}
		ans=min(r-l+1,ans);
	}
	if (ans==INF) cout<<"impossible\n";
	else cout<<ans<<"\n";
	return 0;
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...