답안 #891039

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
891039 2023-12-22T06:42:19 Z Xiaoyang Martian DNA (BOI18_dna) C++17
100 / 100
55 ms 9676 KB
#include<bits/stdc++.h>
using namespace std;
 
typedef long long ll;
 
#define fi first
#define se second
#define pii pair<int,int>
#define pll pair<long long,long long>
#define pb push_back
#define debug(x) cerr<<#x<<"="<<x<<endl
#define pq priority_queue
#define inf 1ll<<60
#define rep(i,a,b) for (ll i=a;i<(b);i++)
#define MP make_pair
#define SZ(x) (int(x.size()))
#define mod 1000000007
#define ALL(x) x.begin(),x.end()
#define endl "\n"
void inc(ll &a,ll b) {a=(a+b)%mod;}
void dec(ll &a,ll b) {a=(a-b+mod)%mod;}
int prod(ll a,ll b) {return ll(a)*ll(b)%mod;}
int lowbit(ll x) {return x&(-x);}
ll p0w(ll base,ll p) {ll ret=1;while(p>0){if (p%2ll==1ll) ret=ret*base%mod;base=base*base%mod;p/=2ll;}return ret;}


const ll maxn=222222;
ll a[maxn];
ll need[maxn];
vector<pll>tmp;
ll cnt[maxn];
ll bad[maxn];
ll n,k,r;
bool check(ll len){
	memset(cnt,0,sizeof cnt);
	memset(bad,0,sizeof bad);
	ll amt=0;
	rep(i,1,len+1)cnt[a[i]]++;
	rep(i,0,k){
		if(cnt[i]<need[i]){
			bad[i]=1;
			amt++;
		}
	}
	if(amt==0)return 1;
	//cout<<endl;
	//rep(i,0,k)cout<<i<<" "<<cnt[i]<<endl;
	//rep(i,0,k)cout<<bad[i]<<" ";
	//debug(amt);
	rep(i,2,n+2-len){
		//debug(i+len-1);
		//cout<<"-------------"<<endl;
		cnt[a[i-1]]--;
		if(cnt[a[i-1]]<need[a[i-1]] and !bad[a[i-1]]){//debug(11);
			amt++;
			bad[a[i-1]]=1;
		}
		cnt[a[i+len-1]]++;
		if(cnt[a[i+len-1]]>=need[a[i+len-1]] and bad[a[i+len-1]]){//debug(22);
			amt--;
			bad[a[i+len-1]]=0;
		}
		//rep(i,0,k)cout<<i<<" "<<cnt[i]<<endl;
		//rep(i,0,k)cout<<bad[i]<<" ";
		//debug(amt);
		if(amt==0){
			//debug(i);
			//debug(i+len);
			return 1;
		}
	}
	return 0;
}
int main(){
	ios::sync_with_stdio(0);
	cin.tie(0);
	//freopen("i.txt","r",stdin);
	cin>>n>>k>>r;
	rep(i,1,n+1)cin>>a[i];
	rep(i,1,r+1){
		ll x,y;cin>>x>>y;
		tmp.pb(MP(x,y));
		need[x]=y;
	}
	if(!check(n)){
		cout<<"impossible"<<endl;
		return 0;
	}
	ll lo=1,hi=n;
	//bsta the length 
	while(lo<hi){
		ll mid=(lo+hi)>>1;
		if(check(mid))hi=mid;
		else lo=mid+1;
	}
	cout<<lo<<endl;
	return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 6744 KB Output is correct
2 Correct 1 ms 6748 KB Output is correct
3 Correct 1 ms 6744 KB Output is correct
4 Correct 1 ms 6748 KB Output is correct
5 Correct 1 ms 6748 KB Output is correct
6 Correct 1 ms 6744 KB Output is correct
7 Correct 1 ms 6748 KB Output is correct
8 Correct 2 ms 6748 KB Output is correct
9 Correct 2 ms 6748 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 6796 KB Output is correct
2 Correct 2 ms 6744 KB Output is correct
3 Correct 2 ms 6576 KB Output is correct
4 Correct 2 ms 6748 KB Output is correct
5 Correct 2 ms 6748 KB Output is correct
6 Correct 3 ms 6748 KB Output is correct
7 Correct 2 ms 6584 KB Output is correct
8 Correct 2 ms 6748 KB Output is correct
9 Correct 1 ms 6748 KB Output is correct
10 Correct 1 ms 6748 KB Output is correct
11 Correct 1 ms 6700 KB Output is correct
12 Correct 1 ms 6748 KB Output is correct
13 Correct 2 ms 6748 KB Output is correct
14 Correct 2 ms 6748 KB Output is correct
15 Correct 2 ms 7000 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 14 ms 7004 KB Output is correct
2 Correct 23 ms 7004 KB Output is correct
3 Correct 15 ms 7004 KB Output is correct
4 Correct 17 ms 7248 KB Output is correct
5 Correct 22 ms 7516 KB Output is correct
6 Correct 13 ms 7244 KB Output is correct
7 Correct 9 ms 7124 KB Output is correct
8 Correct 29 ms 7516 KB Output is correct
9 Correct 19 ms 7184 KB Output is correct
10 Correct 25 ms 7004 KB Output is correct
11 Correct 2 ms 6748 KB Output is correct
12 Correct 3 ms 6748 KB Output is correct
13 Correct 2 ms 6580 KB Output is correct
14 Correct 2 ms 6748 KB Output is correct
15 Correct 2 ms 7000 KB Output is correct
16 Correct 2 ms 6620 KB Output is correct
17 Correct 1 ms 6748 KB Output is correct
18 Correct 2 ms 6748 KB Output is correct
19 Correct 2 ms 6748 KB Output is correct
20 Correct 1 ms 6748 KB Output is correct
21 Correct 1 ms 6748 KB Output is correct
22 Correct 1 ms 6748 KB Output is correct
23 Correct 1 ms 6748 KB Output is correct
24 Correct 1 ms 6748 KB Output is correct
25 Correct 2 ms 6748 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 30 ms 9136 KB Output is correct
2 Correct 32 ms 8660 KB Output is correct
3 Correct 31 ms 7852 KB Output is correct
4 Correct 10 ms 7004 KB Output is correct
5 Correct 25 ms 9164 KB Output is correct
6 Correct 55 ms 9676 KB Output is correct
7 Correct 18 ms 7512 KB Output is correct
8 Correct 29 ms 7904 KB Output is correct
9 Correct 13 ms 7124 KB Output is correct
10 Correct 23 ms 7504 KB Output is correct
11 Correct 15 ms 7252 KB Output is correct
12 Correct 16 ms 7004 KB Output is correct
13 Correct 21 ms 7516 KB Output is correct
14 Correct 12 ms 7004 KB Output is correct
15 Correct 10 ms 7260 KB Output is correct
16 Correct 28 ms 7716 KB Output is correct
17 Correct 18 ms 7512 KB Output is correct
18 Correct 25 ms 7248 KB Output is correct
19 Correct 2 ms 6748 KB Output is correct
20 Correct 2 ms 6748 KB Output is correct
21 Correct 2 ms 6800 KB Output is correct
22 Correct 3 ms 6748 KB Output is correct
23 Correct 2 ms 6748 KB Output is correct
24 Correct 2 ms 6748 KB Output is correct
25 Correct 2 ms 6576 KB Output is correct
26 Correct 1 ms 6748 KB Output is correct
27 Correct 2 ms 6744 KB Output is correct
28 Correct 1 ms 6748 KB Output is correct
29 Correct 1 ms 6748 KB Output is correct
30 Correct 1 ms 6748 KB Output is correct
31 Correct 1 ms 6748 KB Output is correct
32 Correct 2 ms 6748 KB Output is correct
33 Correct 2 ms 6748 KB Output is correct