답안 #728007

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
728007 2023-04-21T19:07:14 Z WonderfulWhale Martian DNA (BOI18_dna) C++17
100 / 100
46 ms 8128 KB
#include<bits/stdc++.h>
using namespace std;

#define int int64_t
#define pb push_back
#define st first
#define nd second
#define pii pair<int, int>
#define all(x) (x).begin(), (x).end()
#define sz(x) (int)(x).size()

const int MAXN = 200009;

int cnt[MAXN];
int sum[MAXN];
int cur[MAXN];
int tab[MAXN];

int32_t main() {
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);

	int n, k, r;
	cin >> n >> k >> r;
	for(int i=0;i<n;i++) {
		cin >> tab[i];
		sum[tab[i]]++;
	}
	for(int i=0;i<r;i++) {
		int a, b;
		cin >> a >> b;
		cnt[a] = b;
		if(sum[a]<b) {
			cout << "impossible\n";
			return 0;
		}
	}
	int R = -1;
	int bad_cnt = r;
	int ans = 1e9;
	for(int L=0;L<n;L++) {
		while(R+1<n && bad_cnt) {
			R++;
			cur[tab[R]]++;
			if(cur[tab[R]]==cnt[tab[R]]) {
				bad_cnt--;
			}
		}
		if(bad_cnt==0) {
			ans = min(ans, R-L+1);
		}
		cur[tab[L]]--;
		if(cur[tab[L]]==cnt[tab[L]]-1) {
			bad_cnt++;
		}
	}
	cout << ans << "\n";
}


# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 328 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 1 ms 332 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 468 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 1 ms 328 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 1 ms 328 KB Output is correct
12 Correct 0 ms 340 KB Output is correct
13 Correct 1 ms 336 KB Output is correct
14 Correct 0 ms 336 KB Output is correct
15 Correct 1 ms 332 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 14 ms 2304 KB Output is correct
2 Correct 17 ms 2208 KB Output is correct
3 Correct 15 ms 2296 KB Output is correct
4 Correct 13 ms 2260 KB Output is correct
5 Correct 20 ms 4280 KB Output is correct
6 Correct 13 ms 2272 KB Output is correct
7 Correct 12 ms 2408 KB Output is correct
8 Correct 25 ms 6220 KB Output is correct
9 Correct 16 ms 2924 KB Output is correct
10 Correct 13 ms 2268 KB Output is correct
11 Correct 1 ms 336 KB Output is correct
12 Correct 1 ms 340 KB Output is correct
13 Correct 1 ms 348 KB Output is correct
14 Correct 1 ms 468 KB Output is correct
15 Correct 1 ms 340 KB Output is correct
16 Correct 1 ms 340 KB Output is correct
17 Correct 1 ms 340 KB Output is correct
18 Correct 1 ms 328 KB Output is correct
19 Correct 1 ms 340 KB Output is correct
20 Correct 1 ms 340 KB Output is correct
21 Correct 1 ms 340 KB Output is correct
22 Correct 1 ms 340 KB Output is correct
23 Correct 1 ms 340 KB Output is correct
24 Correct 1 ms 340 KB Output is correct
25 Correct 1 ms 340 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 33 ms 5460 KB Output is correct
2 Correct 25 ms 4812 KB Output is correct
3 Correct 23 ms 4504 KB Output is correct
4 Correct 13 ms 2280 KB Output is correct
5 Correct 23 ms 4044 KB Output is correct
6 Correct 46 ms 8128 KB Output is correct
7 Correct 18 ms 3084 KB Output is correct
8 Correct 19 ms 3448 KB Output is correct
9 Correct 11 ms 2284 KB Output is correct
10 Correct 17 ms 2264 KB Output is correct
11 Correct 13 ms 2268 KB Output is correct
12 Correct 15 ms 2308 KB Output is correct
13 Correct 22 ms 4256 KB Output is correct
14 Correct 16 ms 2244 KB Output is correct
15 Correct 17 ms 2452 KB Output is correct
16 Correct 31 ms 6312 KB Output is correct
17 Correct 17 ms 2956 KB Output is correct
18 Correct 12 ms 2188 KB Output is correct
19 Correct 1 ms 340 KB Output is correct
20 Correct 1 ms 340 KB Output is correct
21 Correct 1 ms 340 KB Output is correct
22 Correct 1 ms 408 KB Output is correct
23 Correct 2 ms 340 KB Output is correct
24 Correct 1 ms 336 KB Output is correct
25 Correct 0 ms 340 KB Output is correct
26 Correct 1 ms 340 KB Output is correct
27 Correct 1 ms 340 KB Output is correct
28 Correct 1 ms 340 KB Output is correct
29 Correct 1 ms 340 KB Output is correct
30 Correct 1 ms 340 KB Output is correct
31 Correct 1 ms 340 KB Output is correct
32 Correct 1 ms 332 KB Output is correct
33 Correct 1 ms 340 KB Output is correct