답안 #403984

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
403984 2021-05-13T16:17:34 Z rama_pang Martian DNA (BOI18_dna) C++17
100 / 100
43 ms 4540 KB
#include <bits/stdc++.h>
using namespace std;

int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);

  int N, K, R;
  cin >> N >> K >> R;

  vector<int> A(N);
  for (int i = 0; i < N; i++) {
    cin >> A[i];
  }

  vector<int> B(K);
  for (int i = 0; i < R; i++) {
    int x, y;
    cin >> x >> y;
    B[x] = y;
  }

  int ans = N + 1;

  int bad = R;
  vector<int> freq(K);
  const auto Modify = [&](int k, int sgn) {
    bad -= freq[k] < B[k];
    freq[k] += sgn;
    bad += freq[k] < B[k];
  };

  for (int i = 0, j = 0; i < N; i++) {
    Modify(A[i], +1);
    while (bad == 0) {
      Modify(A[j], -1);
      if (bad == 0) {
        j += 1;
      } else {
        Modify(A[j], +1);
        break;
      }
    }
    if (bad == 0) {
      ans = min(ans, i - j + 1);
    }
  }

  if (ans > N) {
    cout << "impossible\n";
  } else {
    cout << ans << '\n';
  }
  return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
5 Correct 1 ms 204 KB Output is correct
6 Correct 1 ms 204 KB Output is correct
7 Correct 1 ms 204 KB Output is correct
8 Correct 1 ms 204 KB Output is correct
9 Correct 1 ms 316 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 320 KB Output is correct
2 Correct 1 ms 332 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
4 Correct 1 ms 332 KB Output is correct
5 Correct 1 ms 324 KB Output is correct
6 Correct 1 ms 332 KB Output is correct
7 Correct 2 ms 204 KB Output is correct
8 Correct 1 ms 204 KB Output is correct
9 Correct 1 ms 204 KB Output is correct
10 Correct 1 ms 204 KB Output is correct
11 Correct 1 ms 204 KB Output is correct
12 Correct 1 ms 204 KB Output is correct
13 Correct 1 ms 204 KB Output is correct
14 Correct 1 ms 204 KB Output is correct
15 Correct 1 ms 204 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 17 ms 1484 KB Output is correct
2 Correct 18 ms 1484 KB Output is correct
3 Correct 23 ms 1484 KB Output is correct
4 Correct 19 ms 1456 KB Output is correct
5 Correct 24 ms 2776 KB Output is correct
6 Correct 17 ms 1484 KB Output is correct
7 Correct 19 ms 1608 KB Output is correct
8 Correct 29 ms 3908 KB Output is correct
9 Correct 22 ms 2116 KB Output is correct
10 Correct 18 ms 1476 KB Output is correct
11 Correct 2 ms 332 KB Output is correct
12 Correct 1 ms 332 KB Output is correct
13 Correct 1 ms 324 KB Output is correct
14 Correct 1 ms 324 KB Output is correct
15 Correct 1 ms 332 KB Output is correct
16 Correct 1 ms 332 KB Output is correct
17 Correct 1 ms 204 KB Output is correct
18 Correct 1 ms 204 KB Output is correct
19 Correct 1 ms 312 KB Output is correct
20 Correct 1 ms 204 KB Output is correct
21 Correct 1 ms 204 KB Output is correct
22 Correct 1 ms 204 KB Output is correct
23 Correct 1 ms 204 KB Output is correct
24 Correct 1 ms 204 KB Output is correct
25 Correct 1 ms 316 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 38 ms 3392 KB Output is correct
2 Correct 34 ms 3140 KB Output is correct
3 Correct 28 ms 2748 KB Output is correct
4 Correct 22 ms 1480 KB Output is correct
5 Correct 43 ms 4032 KB Output is correct
6 Correct 43 ms 4540 KB Output is correct
7 Correct 22 ms 2116 KB Output is correct
8 Correct 26 ms 2380 KB Output is correct
9 Correct 17 ms 1484 KB Output is correct
10 Correct 18 ms 1480 KB Output is correct
11 Correct 20 ms 1476 KB Output is correct
12 Correct 18 ms 1476 KB Output is correct
13 Correct 25 ms 2888 KB Output is correct
14 Correct 19 ms 1480 KB Output is correct
15 Correct 19 ms 1608 KB Output is correct
16 Correct 26 ms 3912 KB Output is correct
17 Correct 23 ms 2068 KB Output is correct
18 Correct 18 ms 1476 KB Output is correct
19 Correct 1 ms 332 KB Output is correct
20 Correct 1 ms 332 KB Output is correct
21 Correct 1 ms 332 KB Output is correct
22 Correct 1 ms 332 KB Output is correct
23 Correct 1 ms 332 KB Output is correct
24 Correct 1 ms 332 KB Output is correct
25 Correct 1 ms 204 KB Output is correct
26 Correct 1 ms 204 KB Output is correct
27 Correct 1 ms 204 KB Output is correct
28 Correct 1 ms 204 KB Output is correct
29 Correct 1 ms 204 KB Output is correct
30 Correct 1 ms 204 KB Output is correct
31 Correct 1 ms 204 KB Output is correct
32 Correct 1 ms 204 KB Output is correct
33 Correct 1 ms 204 KB Output is correct