Submission #653703

# Submission time Handle Problem Language Result Execution time Memory
653703 2022-10-27T18:05:23 Z Juan Martian DNA (BOI18_dna) C++14
0 / 100
178 ms 5208 KB
#include<bits/stdc++.h>
using namespace std;
const int maxn = 2e5 + 5;
#define pii pair<int, int>
#define ll long long

int v[maxn], need[maxn];
map<int, int> mp;

int main(){
	int n, k, m; cin >> n >> k >> m;
	for(int i = 0; i < n; i++) cin >> v[i];
	for(int i = 0; i < m; i++){
		int a, b; cin >> a >> b;
		need[a] = b;
	}

	int l = 0, r = 0;
	int ans = n+1;
	while(l<n){
		int invalid_cnt = m;
		bool term = false;
		while(invalid_cnt){
			if(r==n) {term = true; break;}
			mp[v[r]]++;
			if(mp[v[r]]==need[v[r]]) invalid_cnt--;
			r++;
		}
		if(term==true) break;
		while(true){
			if(mp[v[l]]==need[v[l]]) break;
			mp[v[l]]--;
			l++;
		}
		ans = min(ans, r-l);
	}

	if(ans == n+1) cout << "impossible\n";
	else cout << ans << '\n';
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Incorrect 0 ms 212 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 212 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 31 ms 1068 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 178 ms 5208 KB Output isn't correct
2 Halted 0 ms 0 KB -