답안 #862797

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
862797 2023-10-19T03:55:15 Z maks007 Martian DNA (BOI18_dna) C++14
100 / 100
666 ms 4660 KB
#include "bits/stdc++.h"

using namespace std;

signed main () {
	int n, k, q;
	cin >> n >> k >> q;
	vector <int> a(n);
	for(int i = 0; i < n; i ++) cin >> a[i];
	int cnt[k];
	memset(cnt, 0, sizeof(cnt));
	while(q --) {
		int val, sz;
		cin >> val >> sz;
		cnt[val] += sz;
	}
	int mn = 1e9, pref[k];
	memset(pref, 0, sizeof(pref));
	int l = 0, r = 0;
	for(;r<n;r++){
		pref[a[r]] ++;
		for(int j = 0; j < k; j ++) {
			if(cnt[j] <= pref[j]) continue;
			goto end;
		}
		break;
		end:;
	}
	if(r == n) {
		cout << "impossible";
		return 0;
	}
	mn = r-l+1;
	for(;r < n;) {
		while(1) {
			if(l == n) {
				break;
				// goto end2;
			}
			pref[a[l]] --;
			// cout << pref[a[l]] << " ";
			if(pref[a[l]] < cnt[a[l]]) {
				pref[a[l]] ++;
				// l--;
				break;
			}
			l ++;
		}
		// cout << l << " " << r << "\n";
		mn = min(mn, r-l+1);
		r++;
		if(r == n) break;
		pref[a[r]] ++;
	}
	cout << mn;
 	return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 344 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 2 ms 348 KB Output is correct
4 Correct 3 ms 448 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Correct 1 ms 440 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 1 ms 348 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 22 ms 1372 KB Output is correct
2 Correct 24 ms 1372 KB Output is correct
3 Correct 24 ms 1628 KB Output is correct
4 Correct 23 ms 1628 KB Output is correct
5 Correct 491 ms 2900 KB Output is correct
6 Correct 25 ms 1372 KB Output is correct
7 Correct 25 ms 1800 KB Output is correct
8 Correct 655 ms 4032 KB Output is correct
9 Correct 124 ms 2384 KB Output is correct
10 Correct 22 ms 1368 KB Output is correct
11 Correct 1 ms 344 KB Output is correct
12 Correct 1 ms 348 KB Output is correct
13 Correct 2 ms 348 KB Output is correct
14 Correct 3 ms 448 KB Output is correct
15 Correct 1 ms 348 KB Output is correct
16 Correct 1 ms 444 KB Output is correct
17 Correct 0 ms 440 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 0 ms 348 KB Output is correct
21 Correct 0 ms 348 KB Output is correct
22 Correct 0 ms 348 KB Output is correct
23 Correct 0 ms 348 KB Output is correct
24 Correct 0 ms 348 KB Output is correct
25 Correct 0 ms 348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 63 ms 3420 KB Output is correct
2 Correct 58 ms 3252 KB Output is correct
3 Correct 47 ms 2728 KB Output is correct
4 Correct 24 ms 1372 KB Output is correct
5 Correct 75 ms 4136 KB Output is correct
6 Correct 79 ms 4660 KB Output is correct
7 Correct 38 ms 2132 KB Output is correct
8 Correct 55 ms 2340 KB Output is correct
9 Correct 22 ms 1372 KB Output is correct
10 Correct 24 ms 1368 KB Output is correct
11 Correct 24 ms 1628 KB Output is correct
12 Correct 23 ms 1640 KB Output is correct
13 Correct 496 ms 2980 KB Output is correct
14 Correct 27 ms 1624 KB Output is correct
15 Correct 27 ms 1716 KB Output is correct
16 Correct 666 ms 4028 KB Output is correct
17 Correct 122 ms 2132 KB Output is correct
18 Correct 22 ms 1368 KB Output is correct
19 Correct 1 ms 348 KB Output is correct
20 Correct 1 ms 348 KB Output is correct
21 Correct 2 ms 348 KB Output is correct
22 Correct 4 ms 452 KB Output is correct
23 Correct 1 ms 448 KB Output is correct
24 Correct 1 ms 348 KB Output is correct
25 Correct 0 ms 348 KB Output is correct
26 Correct 0 ms 348 KB Output is correct
27 Correct 0 ms 348 KB Output is correct
28 Correct 0 ms 348 KB Output is correct
29 Correct 0 ms 348 KB Output is correct
30 Correct 0 ms 348 KB Output is correct
31 Correct 0 ms 348 KB Output is correct
32 Correct 0 ms 348 KB Output is correct
33 Correct 0 ms 348 KB Output is correct