Submission #927136

# Submission time Handle Problem Language Result Execution time Memory
927136 2024-02-14T09:58:12 Z vjudge1 Martian DNA (BOI18_dna) C++17
100 / 100
427 ms 36672 KB
#include <bits/stdc++.h>

using namespace std;

#define all(a) a.begin(),a.end()
#define pb push_back
#define vt vector
#define endl '\n'
typedef long long ll;

const ll mod=1e9+7;
const ll inf=1e9+7;
const int N=4e5+4;

int n,k,r;
int a[N];
map<int,int>mp,cur;
set<int>st[N];
multiset<int>mst;

void solve(){
	cin>>n>>k>>r;
	for(int i=1; i<=n; ++i){
		cin>>a[i];
	}
	ll all=0;
	for(int i=1; i<=r; ++i){
		int tp,cn;
		cin>>tp>>cn;
		mp[tp]=cn;
		for(int x=0; x<cn; ++x) {
			mst.insert(tp);
			++all;
			if(all>n){
				cout<<"impossible\n";
				return;
			}
		}
	}
	int l=0,r=0;
	int ans=inf;
	while(1){
		if(l==r && r==n) break;
		//cout<<l<<' '<<r<<endl;
		//cout<<mst.size()<<endl;
		while(r+1<=n && mst.size()){
			++r;
			auto pos=mst.find(a[r]);
			cur[a[r]]++;
			//cout<<a[r]<<"  "<<cur[a[r]]<<endl;
			if(pos!=mst.end()) mst.erase(pos);
		}
		if(r==n && mst.size()) {
			break;
		}
		ans=min(ans,r-l);
		while(l+1<=r){
			while(l+1<=r && mp[a[l+1]]==0) ++l;
			ans=min(ans,r-l);
			if(l+1>r) break; 
			++l;
			cur[a[l]]--;
			//cout<<a[l]<<' '<<cur[a[l]]<<endl;
		//	return;
			if(cur[a[l]]<mp[a[l]]) {
				mst.insert(a[l]);
				break;
			}
			ans=min(ans,r-l);
		}
	}
	if(ans==inf){
		cout<<"impossible\n";
		return;
	}
	cout<<ans<<endl;
}
			
int main(){
	int tt=1;
	//cin>>tt;
	while(tt--) {
		solve();
	}
}
# Verdict Execution time Memory Grader output
1 Correct 7 ms 19032 KB Output is correct
2 Correct 5 ms 19032 KB Output is correct
3 Correct 4 ms 19036 KB Output is correct
4 Correct 4 ms 19240 KB Output is correct
5 Correct 4 ms 19036 KB Output is correct
6 Correct 4 ms 19072 KB Output is correct
7 Correct 4 ms 19036 KB Output is correct
8 Correct 6 ms 19032 KB Output is correct
9 Correct 4 ms 19032 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 19036 KB Output is correct
2 Correct 6 ms 19312 KB Output is correct
3 Correct 7 ms 19292 KB Output is correct
4 Correct 9 ms 19544 KB Output is correct
5 Correct 7 ms 19292 KB Output is correct
6 Correct 5 ms 19036 KB Output is correct
7 Correct 4 ms 19036 KB Output is correct
8 Correct 4 ms 19036 KB Output is correct
9 Correct 4 ms 19036 KB Output is correct
10 Correct 4 ms 19036 KB Output is correct
11 Correct 4 ms 19036 KB Output is correct
12 Correct 5 ms 19036 KB Output is correct
13 Correct 4 ms 19036 KB Output is correct
14 Correct 4 ms 19032 KB Output is correct
15 Correct 4 ms 19036 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 46 ms 24148 KB Output is correct
2 Correct 39 ms 21840 KB Output is correct
3 Correct 37 ms 19800 KB Output is correct
4 Correct 45 ms 22744 KB Output is correct
5 Correct 111 ms 27472 KB Output is correct
6 Correct 98 ms 29380 KB Output is correct
7 Correct 48 ms 20036 KB Output is correct
8 Correct 146 ms 34296 KB Output is correct
9 Correct 74 ms 20580 KB Output is correct
10 Correct 61 ms 23364 KB Output is correct
11 Correct 6 ms 19032 KB Output is correct
12 Correct 6 ms 19288 KB Output is correct
13 Correct 5 ms 19292 KB Output is correct
14 Correct 9 ms 19548 KB Output is correct
15 Correct 5 ms 19292 KB Output is correct
16 Correct 4 ms 19036 KB Output is correct
17 Correct 4 ms 19036 KB Output is correct
18 Correct 4 ms 19036 KB Output is correct
19 Correct 4 ms 19036 KB Output is correct
20 Correct 5 ms 19200 KB Output is correct
21 Correct 4 ms 19032 KB Output is correct
22 Correct 4 ms 19288 KB Output is correct
23 Correct 4 ms 19036 KB Output is correct
24 Correct 4 ms 19036 KB Output is correct
25 Correct 6 ms 19036 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 286 ms 27496 KB Output is correct
2 Correct 201 ms 25428 KB Output is correct
3 Correct 144 ms 25880 KB Output is correct
4 Correct 37 ms 19992 KB Output is correct
5 Correct 86 ms 29196 KB Output is correct
6 Correct 427 ms 36672 KB Output is correct
7 Correct 116 ms 23888 KB Output is correct
8 Correct 153 ms 22612 KB Output is correct
9 Correct 62 ms 24212 KB Output is correct
10 Correct 39 ms 21844 KB Output is correct
11 Correct 36 ms 19800 KB Output is correct
12 Correct 44 ms 22620 KB Output is correct
13 Correct 131 ms 27476 KB Output is correct
14 Correct 71 ms 29264 KB Output is correct
15 Correct 37 ms 20060 KB Output is correct
16 Correct 143 ms 34260 KB Output is correct
17 Correct 70 ms 20584 KB Output is correct
18 Correct 46 ms 23388 KB Output is correct
19 Correct 5 ms 19036 KB Output is correct
20 Correct 5 ms 19292 KB Output is correct
21 Correct 5 ms 19292 KB Output is correct
22 Correct 6 ms 19544 KB Output is correct
23 Correct 5 ms 19292 KB Output is correct
24 Correct 6 ms 19068 KB Output is correct
25 Correct 4 ms 19040 KB Output is correct
26 Correct 4 ms 19036 KB Output is correct
27 Correct 5 ms 19036 KB Output is correct
28 Correct 4 ms 19236 KB Output is correct
29 Correct 4 ms 19032 KB Output is correct
30 Correct 4 ms 19036 KB Output is correct
31 Correct 4 ms 19036 KB Output is correct
32 Correct 6 ms 19036 KB Output is correct
33 Correct 4 ms 19032 KB Output is correct