답안 #1013792

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1013792 2024-07-04T05:55:28 Z vjudge1 Martian DNA (BOI18_dna) C++17
100 / 100
19 ms 2468 KB
#include <bits/stdc++.h>
#define ll long long
#define pii pair<int, int>
using namespace std;

const int N = 2e5+5, INF = 1e9;

int n, k, rr;
int a[N];
int q[N];

int cur[N];

int main()
{
	ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);
	cin >> n >> k >> rr;
	for (int i = 1; i <= n; cin >> a[i++]);
	for (int i = 1, b; i <= rr; cin >> b >> q[b], i++);
	int sat = (q[a[1]] && ++cur[a[1]] == q[a[1]]);
	int l = 1, r = 1;
	int sol = INF;
	while (r <= n) {
		//cerr << sat << ": " << l << ' ' << r << endl;
		if (sat == rr && l <= r) {
			sol = min(sol, r-l+1);
			if (q[a[l]] && cur[a[l]] == q[a[l]]) sat--;
			cur[a[l]]--;
			l++;
		} else {
			r++;
			cur[a[r]]++;
			if (q[a[r]] && cur[a[r]] == q[a[r]]) sat++;
		}
		if (r == n) break;
	}
	while (l <= n && sat == rr) {
		sol = min(sol, r-l+1);
		if (q[a[l]] && cur[a[l]] == q[a[l]]) break;
		cur[a[l]]--;
		l++;
	}
	cout << (sol == INF ? "impossible" : to_string(sol));
}
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 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 348 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 0 ms 484 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Correct 1 ms 344 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 1 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 0 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 7 ms 1116 KB Output is correct
2 Correct 8 ms 1236 KB Output is correct
3 Correct 10 ms 1116 KB Output is correct
4 Correct 10 ms 1084 KB Output is correct
5 Correct 10 ms 1468 KB Output is correct
6 Correct 7 ms 1112 KB Output is correct
7 Correct 8 ms 1248 KB Output is correct
8 Correct 12 ms 1960 KB Output is correct
9 Correct 9 ms 1116 KB Output is correct
10 Correct 12 ms 1116 KB Output is correct
11 Correct 1 ms 344 KB Output is correct
12 Correct 0 ms 344 KB Output is correct
13 Correct 1 ms 348 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 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 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 372 KB Output is correct
22 Correct 1 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 17 ms 1884 KB Output is correct
2 Correct 14 ms 1628 KB Output is correct
3 Correct 13 ms 1628 KB Output is correct
4 Correct 7 ms 1116 KB Output is correct
5 Correct 17 ms 1900 KB Output is correct
6 Correct 19 ms 2468 KB Output is correct
7 Correct 10 ms 1072 KB Output is correct
8 Correct 13 ms 1372 KB Output is correct
9 Correct 10 ms 1116 KB Output is correct
10 Correct 8 ms 1116 KB Output is correct
11 Correct 11 ms 1096 KB Output is correct
12 Correct 9 ms 1116 KB Output is correct
13 Correct 10 ms 1468 KB Output is correct
14 Correct 7 ms 1100 KB Output is correct
15 Correct 9 ms 1116 KB Output is correct
16 Correct 12 ms 1880 KB Output is correct
17 Correct 13 ms 1116 KB Output is correct
18 Correct 7 ms 1112 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 1 ms 348 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 1 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