답안 #307088

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
307088 2020-09-27T02:03:07 Z Rainbowbunny Martian DNA (BOI18_dna) C++17
100 / 100
70 ms 4600 KB
#include <bits/stdc++.h>
#define mp make_pair
#define eb emplace_back
#define fi first
#define se second
using namespace std;
using cd = complex <double>;
 
typedef pair <int, int> pii;
const int N = 3e3 + 5;
const long long INF = 1e18;
const int mod = 998244353;//786433;//998244353;
const double Pi = acos(-1);
 
 
void Fastio()
{
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
}
 
int n, k, rt;
int a[200005], cnt[200005], b[200005];
 
int main()
{
	Fastio();
	cin >> n >> k >> rt;
	for(int i = 0; i < n; i++)
	{
		cin >> a[i];
	}
	for(int i = 0; i < rt; i++)
	{
		int temp;
		cin >> temp;
		cin >> b[temp];
	}
	int l = 1, r = n + 1;
	while(l < r)
	{
		int mid = (l + r) >> 1;
		int cc = 0;
		for(int i = 0; i <= k; i++)
		{
			cnt[i] = 0;
		}
		for(int i = 0; i < mid; i++)
		{
			cnt[a[i]]++;
			if(cnt[a[i]] == b[a[i]])
			{
				cc++;
			}
		}
		bool ok = false;
		if(cc == rt)
		{
			ok = true;
		}
		for(int i = mid; i < n; i++)
		{
			if(cnt[a[i - mid]] == b[a[i - mid]])
			{
				cc--;
			}
			cnt[a[i - mid]]--;
			cnt[a[i]]++;
			if(cnt[a[i]] == b[a[i]])
			{
				cc++;
			}
			if(cc == rt or ok == true)
			{
				ok = true;
				break;
			}
		}
		if(ok)
		{
			r = mid;
		}
		else
		{
			l = mid + 1;
		}
	} 	
	if(l == n + 1)
	{
		cout << "impossible";
		return 0;
	}
	cout << l;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 0 ms 384 KB Output is correct
3 Correct 1 ms 384 KB Output is correct
4 Correct 1 ms 384 KB Output is correct
5 Correct 1 ms 384 KB Output is correct
6 Correct 1 ms 384 KB Output is correct
7 Correct 1 ms 384 KB Output is correct
8 Correct 1 ms 384 KB Output is correct
9 Correct 0 ms 384 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 1 ms 384 KB Output is correct
3 Correct 1 ms 384 KB Output is correct
4 Correct 1 ms 416 KB Output is correct
5 Correct 1 ms 384 KB Output is correct
6 Correct 1 ms 384 KB Output is correct
7 Correct 1 ms 384 KB Output is correct
8 Correct 1 ms 384 KB Output is correct
9 Correct 0 ms 384 KB Output is correct
10 Correct 1 ms 384 KB Output is correct
11 Correct 1 ms 384 KB Output is correct
12 Correct 1 ms 384 KB Output is correct
13 Correct 0 ms 384 KB Output is correct
14 Correct 1 ms 384 KB Output is correct
15 Correct 0 ms 384 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 30 ms 1592 KB Output is correct
2 Correct 29 ms 1536 KB Output is correct
3 Correct 20 ms 1536 KB Output is correct
4 Correct 27 ms 1536 KB Output is correct
5 Correct 36 ms 2680 KB Output is correct
6 Correct 25 ms 1536 KB Output is correct
7 Correct 27 ms 1664 KB Output is correct
8 Correct 46 ms 3348 KB Output is correct
9 Correct 33 ms 2168 KB Output is correct
10 Correct 32 ms 1536 KB Output is correct
11 Correct 1 ms 384 KB Output is correct
12 Correct 1 ms 384 KB Output is correct
13 Correct 1 ms 384 KB Output is correct
14 Correct 1 ms 384 KB Output is correct
15 Correct 1 ms 384 KB Output is correct
16 Correct 1 ms 384 KB Output is correct
17 Correct 1 ms 384 KB Output is correct
18 Correct 1 ms 384 KB Output is correct
19 Correct 0 ms 384 KB Output is correct
20 Correct 1 ms 384 KB Output is correct
21 Correct 1 ms 384 KB Output is correct
22 Correct 1 ms 384 KB Output is correct
23 Correct 1 ms 384 KB Output is correct
24 Correct 1 ms 384 KB Output is correct
25 Correct 1 ms 384 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 45 ms 3576 KB Output is correct
2 Correct 50 ms 3192 KB Output is correct
3 Correct 53 ms 3064 KB Output is correct
4 Correct 14 ms 1536 KB Output is correct
5 Correct 51 ms 4096 KB Output is correct
6 Correct 70 ms 4600 KB Output is correct
7 Correct 35 ms 2176 KB Output is correct
8 Correct 47 ms 2424 KB Output is correct
9 Correct 29 ms 1536 KB Output is correct
10 Correct 29 ms 1536 KB Output is correct
11 Correct 20 ms 1536 KB Output is correct
12 Correct 27 ms 1536 KB Output is correct
13 Correct 35 ms 2688 KB Output is correct
14 Correct 25 ms 1536 KB Output is correct
15 Correct 25 ms 1664 KB Output is correct
16 Correct 44 ms 3200 KB Output is correct
17 Correct 32 ms 2176 KB Output is correct
18 Correct 32 ms 1664 KB Output is correct
19 Correct 1 ms 384 KB Output is correct
20 Correct 1 ms 384 KB Output is correct
21 Correct 1 ms 384 KB Output is correct
22 Correct 1 ms 384 KB Output is correct
23 Correct 1 ms 384 KB Output is correct
24 Correct 1 ms 384 KB Output is correct
25 Correct 1 ms 384 KB Output is correct
26 Correct 1 ms 384 KB Output is correct
27 Correct 1 ms 384 KB Output is correct
28 Correct 1 ms 384 KB Output is correct
29 Correct 1 ms 384 KB Output is correct
30 Correct 1 ms 384 KB Output is correct
31 Correct 0 ms 384 KB Output is correct
32 Correct 1 ms 384 KB Output is correct
33 Correct 1 ms 384 KB Output is correct