답안 #939432

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
939432 2024-03-06T11:10:57 Z Gromp15 Martian DNA (BOI18_dna) C++17
100 / 100
25 ms 4688 KB
#include <bits/stdc++.h>
#define ll long long
#define ar array
#define db double
#define all(x) x.begin(), x.end()
#define sz(x) (int)x.size()
using namespace std;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
#define rint(l, r) uniform_int_distribution<int>(l, r)(rng)
template<typename T> bool ckmin(T &a, const T &b) { return a > b ? a = b, 1 : 0; }
template<typename T> bool ckmax(T &a, const T &b) { return a < b ? a = b, 1 : 0; }
void test_case() {
	int n, k, m;
	cin >> n >> k >> m;
	vector<int> req(k), a(n);
	for (int &x : a) cin >> x;
	for (int i = 0; i < m; i++) { 
		int x, y; cin >> x >> y;
		req[x] = y;
	}
	int good = k - m, to = -1;
	vector<int> have(k);
	int ans = 1e9;
	for (int i = 0; i < n; i++) {
		while (good < k && to+1 < n) {
			if (++have[a[to+1]] == req[a[to+1]]) {
				good++;
			}
			to++;
		}
		if (good == k) {
			ckmin(ans, to - i + 1);
		}
		else break;
		assert(have[a[i]] >= req[a[i]]);
		if (have[a[i]]-- == req[a[i]]) good--;
	}
	if (ans == 1e9) cout << "impossible\n";
	else cout << ans << '\n';




}
int main() {
    cin.tie(0)->sync_with_stdio(0);
    int t = 1;
//    cin >> t;
    while (t--) test_case();
}

# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 344 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 344 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 1 ms 348 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Correct 1 ms 344 KB Output is correct
7 Correct 0 ms 344 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 456 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 1 ms 348 KB Output is correct
14 Correct 1 ms 348 KB Output is correct
15 Correct 0 ms 344 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 8 ms 1624 KB Output is correct
2 Correct 9 ms 1492 KB Output is correct
3 Correct 10 ms 1628 KB Output is correct
4 Correct 9 ms 1628 KB Output is correct
5 Correct 13 ms 2952 KB Output is correct
6 Correct 9 ms 1628 KB Output is correct
7 Correct 9 ms 1628 KB Output is correct
8 Correct 16 ms 3944 KB Output is correct
9 Correct 12 ms 2140 KB Output is correct
10 Correct 10 ms 1500 KB Output is correct
11 Correct 1 ms 344 KB Output is correct
12 Correct 1 ms 348 KB Output is correct
13 Correct 1 ms 348 KB Output is correct
14 Correct 1 ms 348 KB Output is correct
15 Correct 1 ms 348 KB Output is correct
16 Correct 1 ms 348 KB Output is correct
17 Correct 0 ms 348 KB Output is correct
18 Correct 0 ms 464 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 24 ms 3420 KB Output is correct
2 Correct 18 ms 3152 KB Output is correct
3 Correct 16 ms 3144 KB Output is correct
4 Correct 9 ms 1628 KB Output is correct
5 Correct 23 ms 4048 KB Output is correct
6 Correct 25 ms 4688 KB Output is correct
7 Correct 12 ms 2136 KB Output is correct
8 Correct 15 ms 2396 KB Output is correct
9 Correct 9 ms 1628 KB Output is correct
10 Correct 10 ms 1500 KB Output is correct
11 Correct 10 ms 1628 KB Output is correct
12 Correct 9 ms 1628 KB Output is correct
13 Correct 13 ms 2908 KB Output is correct
14 Correct 9 ms 1628 KB Output is correct
15 Correct 10 ms 1624 KB Output is correct
16 Correct 20 ms 3932 KB Output is correct
17 Correct 15 ms 2140 KB Output is correct
18 Correct 9 ms 1624 KB Output is correct
19 Correct 1 ms 348 KB Output is correct
20 Correct 1 ms 348 KB Output is correct
21 Correct 1 ms 348 KB Output is correct
22 Correct 1 ms 348 KB Output is correct
23 Correct 1 ms 348 KB Output is correct
24 Correct 0 ms 600 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 344 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