답안 #891032

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
891032 2023-12-22T06:37:32 Z Xiaoyang Martian DNA (BOI18_dna) C++17
0 / 100
67 ms 8908 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+1-len){
		//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;
	}
	ll lo=1,hi=n+1;
	//bsta the length 
	while(lo<hi){
		ll mid=(lo+hi)>>1;
		if(check(mid))hi=mid;
		else lo=mid+1;
	}
	if(lo==n+1)cout<<"impossible"<<endl;
	else cout<<lo<<endl;
	return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 6748 KB Output is correct
2 Correct 1 ms 6748 KB Output is correct
3 Correct 1 ms 6748 KB Output is correct
4 Correct 1 ms 6748 KB Output is correct
5 Correct 1 ms 6744 KB Output is correct
6 Incorrect 2 ms 6748 KB Output isn't correct
7 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 6748 KB Output is correct
2 Correct 2 ms 6744 KB Output is correct
3 Correct 3 ms 6744 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 6744 KB Output is correct
7 Correct 2 ms 6744 KB Output is correct
8 Correct 2 ms 6748 KB Output is correct
9 Correct 1 ms 6748 KB Output is correct
10 Correct 2 ms 6748 KB Output is correct
11 Correct 1 ms 6748 KB Output is correct
12 Incorrect 2 ms 6748 KB Output isn't correct
13 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 20 ms 7000 KB Output is correct
2 Correct 24 ms 7000 KB Output is correct
3 Correct 14 ms 7004 KB Output is correct
4 Correct 15 ms 7092 KB Output is correct
5 Correct 21 ms 7124 KB Output is correct
6 Correct 12 ms 7000 KB Output is correct
7 Correct 12 ms 7248 KB Output is correct
8 Correct 29 ms 7004 KB Output is correct
9 Correct 21 ms 7004 KB Output is correct
10 Correct 26 ms 7000 KB Output is correct
11 Correct 2 ms 6744 KB Output is correct
12 Correct 2 ms 6744 KB Output is correct
13 Correct 2 ms 6748 KB Output is correct
14 Correct 2 ms 6580 KB Output is correct
15 Correct 2 ms 6744 KB Output is correct
16 Correct 2 ms 6904 KB Output is correct
17 Correct 1 ms 6744 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 2 ms 6748 KB Output is correct
22 Incorrect 1 ms 6748 KB Output isn't correct
23 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 29 ms 8604 KB Output is correct
2 Correct 30 ms 8152 KB Output is correct
3 Correct 35 ms 7512 KB Output is correct
4 Correct 12 ms 7140 KB Output is correct
5 Correct 33 ms 8608 KB Output is correct
6 Correct 67 ms 8908 KB Output is correct
7 Correct 26 ms 7260 KB Output is correct
8 Correct 32 ms 7516 KB Output is correct
9 Correct 17 ms 7248 KB Output is correct
10 Correct 22 ms 7004 KB Output is correct
11 Correct 15 ms 7256 KB Output is correct
12 Correct 15 ms 7000 KB Output is correct
13 Correct 27 ms 7256 KB Output is correct
14 Correct 14 ms 7004 KB Output is correct
15 Correct 12 ms 7004 KB Output is correct
16 Correct 28 ms 7244 KB Output is correct
17 Correct 17 ms 7004 KB Output is correct
18 Correct 29 ms 7000 KB Output is correct
19 Correct 3 ms 6748 KB Output is correct
20 Correct 2 ms 6748 KB Output is correct
21 Correct 2 ms 6748 KB Output is correct
22 Correct 2 ms 6624 KB Output is correct
23 Correct 2 ms 6748 KB Output is correct
24 Correct 3 ms 6756 KB Output is correct
25 Correct 2 ms 6748 KB Output is correct
26 Correct 2 ms 6748 KB Output is correct
27 Correct 2 ms 6744 KB Output is correct
28 Correct 1 ms 6744 KB Output is correct
29 Correct 1 ms 6748 KB Output is correct
30 Incorrect 1 ms 6748 KB Output isn't correct
31 Halted 0 ms 0 KB -