답안 #378352

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
378352 2021-03-16T14:21:58 Z soroush Martian DNA (BOI18_dna) C++17
100 / 100
75 ms 3308 KB
/*
#pragma GCC optimize("O2")
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#pragma GCC target("avx,avx2,sse,sse2,fma")
*/
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef long double ld;
typedef pair<int , int> pii;

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

const int maxn = 2e5 + 100;
const ll mod = 1e9+7;
const ld PI = acos((ld)-1);

#define pb push_back
#define endl '\n'
#define dokme(x) cout << x , exit(0)
#define migmig ios::sync_with_stdio(false),cin.tie(0),cout.tie(0)
#define ms(x , y) memset(x , y , sizeof x)
ll pw(ll a, ll b, ll md = mod){ll res = 1;while(b){if(b&1){res=(a*res)%md;}a=(a*a)%md;b>>=1;}return(res);}

int n , k , r;
int need[maxn];
int a[maxn];
int cnt[maxn];
int res = 0;

void add(int i){
	cnt[a[i]]++;
	if(cnt[a[i]] == 0)res--;
}

void rem(int i){
	if(cnt[a[i]] == 0)res++;
	cnt[a[i]]--;
}

bool chk(int k){
	bool ok = 0;
	for(int i = 1 ; i <= n ; i ++){
		add(i);
		if(i > k)rem(i - k);
		if(res == 0)ok = 1;
	}
	for(int i = n , j = 0 ; j < k ; i -- , j ++)rem(i);
	return(ok);
}

void prep(){
	for(int i = 1 ; i <= k ; i ++)
		cnt[i] = -need[i];
	for(int i = 1 ; i <= k ; i ++)
		res += (cnt[i] < 0);
}

int32_t main(){
	migmig;
	cin >> n >> k >> r;
	for(int i = 1 ; i <= n ; i ++)
		cin >> a[i] , a[i]++;
	for(int i = 1 ; i <= r ; i ++){
		int x , y;
		cin >> x >> y;
		need[x+1] = y;
	}	
	prep();
	int l = 0, r =  n + 1;
	while(r - l > 1){
		int mid = (l + r) / 2;
		if(chk(mid))
			r = mid;
		else
			l = mid;
	}
	if(r == n + 1)dokme("impossible");
	cout << r;
	return(0);
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 492 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
6 Correct 1 ms 364 KB Output is correct
7 Correct 1 ms 364 KB Output is correct
8 Correct 1 ms 364 KB Output is correct
9 Correct 1 ms 364 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 492 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
6 Correct 2 ms 364 KB Output is correct
7 Correct 1 ms 364 KB Output is correct
8 Correct 1 ms 364 KB Output is correct
9 Correct 1 ms 364 KB Output is correct
10 Correct 1 ms 364 KB Output is correct
11 Correct 1 ms 364 KB Output is correct
12 Correct 1 ms 364 KB Output is correct
13 Correct 1 ms 364 KB Output is correct
14 Correct 1 ms 364 KB Output is correct
15 Correct 1 ms 364 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 35 ms 1516 KB Output is correct
2 Correct 34 ms 1476 KB Output is correct
3 Correct 36 ms 1664 KB Output is correct
4 Correct 39 ms 1516 KB Output is correct
5 Correct 48 ms 2284 KB Output is correct
6 Correct 36 ms 1516 KB Output is correct
7 Correct 38 ms 1772 KB Output is correct
8 Correct 50 ms 2796 KB Output is correct
9 Correct 41 ms 2156 KB Output is correct
10 Correct 32 ms 1516 KB Output is correct
11 Correct 1 ms 364 KB Output is correct
12 Correct 1 ms 364 KB Output is correct
13 Correct 1 ms 364 KB Output is correct
14 Correct 1 ms 364 KB Output is correct
15 Correct 1 ms 364 KB Output is correct
16 Correct 1 ms 364 KB Output is correct
17 Correct 1 ms 384 KB Output is correct
18 Correct 1 ms 364 KB Output is correct
19 Correct 1 ms 364 KB Output is correct
20 Correct 1 ms 364 KB Output is correct
21 Correct 1 ms 364 KB Output is correct
22 Correct 1 ms 364 KB Output is correct
23 Correct 1 ms 364 KB Output is correct
24 Correct 1 ms 364 KB Output is correct
25 Correct 1 ms 364 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 57 ms 2540 KB Output is correct
2 Correct 61 ms 2412 KB Output is correct
3 Correct 69 ms 2412 KB Output is correct
4 Correct 35 ms 1516 KB Output is correct
5 Correct 61 ms 2668 KB Output is correct
6 Correct 75 ms 3308 KB Output is correct
7 Correct 45 ms 2028 KB Output is correct
8 Correct 55 ms 2028 KB Output is correct
9 Correct 35 ms 1516 KB Output is correct
10 Correct 34 ms 1516 KB Output is correct
11 Correct 35 ms 1516 KB Output is correct
12 Correct 34 ms 1516 KB Output is correct
13 Correct 44 ms 2316 KB Output is correct
14 Correct 36 ms 1516 KB Output is correct
15 Correct 36 ms 1772 KB Output is correct
16 Correct 50 ms 2668 KB Output is correct
17 Correct 39 ms 1900 KB Output is correct
18 Correct 35 ms 1516 KB Output is correct
19 Correct 1 ms 364 KB Output is correct
20 Correct 1 ms 364 KB Output is correct
21 Correct 1 ms 364 KB Output is correct
22 Correct 1 ms 364 KB Output is correct
23 Correct 2 ms 364 KB Output is correct
24 Correct 1 ms 364 KB Output is correct
25 Correct 1 ms 364 KB Output is correct
26 Correct 1 ms 364 KB Output is correct
27 Correct 1 ms 364 KB Output is correct
28 Correct 1 ms 364 KB Output is correct
29 Correct 1 ms 364 KB Output is correct
30 Correct 1 ms 364 KB Output is correct
31 Correct 1 ms 364 KB Output is correct
32 Correct 1 ms 364 KB Output is correct
33 Correct 1 ms 364 KB Output is correct