Submission #891114

# Submission time Handle Problem Language Result Execution time Memory
891114 2023-12-22T07:55:39 Z Kiameimon_Welt_Rene Martian DNA (BOI18_dna) C++14
0 / 100
35 ms 10068 KB
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define pii pair<int,int>
#define elif else if
#define dbg(v)\
	cout << "line(" << __LINE__ << ") -> " << #v << " = " << (v) << endl;
	
signed main() {
	ios_base::sync_with_stdio(false); cin.tie(0);
	
	int n, k, R; cin >> n >> k >> R;
	int req[n], cnt[n], arr[n], sz = 0;
	unordered_set<int> nums;
	fill(req, req+n, 0); fill(cnt, cnt+n, 0);
	for(int i = 0; i < n; i++) cin >> arr[i];
	for(int i = 0; i < R; i++){
		int b, q; cin >> b >> q; sz += q;
		req[b] = q; nums.insert(b);
	}
	if(sz > n){cout << "impossible"; return 0;}
	if(sz == n){
		for(int i = 0; i < n; i++){
			
		}
	}
	int l = 0, r = 0, ans = LLONG_MAX;
	while(r < n){
		while(!nums.empty() && r < n){
			int val = arr[r]; cnt[val]++;
			if(req[val] != 0 && cnt[val] >= req[val])nums.erase(val);
			if(!nums.empty() && r < n) r++;
		}
		if(r == n) break;
		ans = min(ans, r-l+1);
		int val = arr[l]; cnt[val]--;
		if(req[val] != 0 && cnt[val] < req[val]) nums.insert(val);
		l++;
	}
	while(l < n-sz && nums.empty()){
		ans = min(ans, r-l+1);
		int val = arr[l]; cnt[val]--;
		if(cnt[val] < req[val]) break;
		l++;		
	}
	
	if(ans == LLONG_MAX){cout << "impossible"; return 0;}
	cout << ans;
	
	return 0;
}
# Verdict Execution time Memory Grader output
1 Runtime error 1 ms 348 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 1 ms 604 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 28 ms 10068 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 35 ms 8236 KB Output isn't correct
2 Halted 0 ms 0 KB -