Submission #894251

# Submission time Handle Problem Language Result Execution time Memory
894251 2023-12-28T03:06:58 Z box Martian DNA (BOI18_dna) C++17
100 / 100
33 ms 4844 KB
#include <iostream>
using namespace std;
 
const int N = 2e5;
 
namespace ds {
int c[N], g[N], z;
 
void add(int x) {
  if (g[x] > 0) z -= ++c[x] == g[x];
}
void rem(int x) {
  if (g[x] > 0) z += c[x]-- == g[x];
}
}  // namespace ds
 
int main() {
  ios::sync_with_stdio(0), cin.tie(0);
  int n, k, m;
  cin >> n >> k >> m;
  static int a[N];
  for (int i = 0; i < n; i++) cin >> a[i];
  for (int h = 0; h < m; h++) {
    int i;
    cin >> i;
    cin >> ds::g[i];
  }
  ds::z = m;
  int x = n + 1;
  for (int i = 0, j = 0; i < n; i++) {
    while (j < n && ds::z > 0) ds::add(a[j++]);
    if (ds::z == 0) x = min(x, j - i);
    ds::rem(a[i]);
  }
  if (x == n + 1)
    cout << "impossible\n";
  else
    cout << x << '\n';
  return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2396 KB Output is correct
2 Correct 1 ms 2396 KB Output is correct
3 Correct 1 ms 2512 KB Output is correct
4 Correct 1 ms 2392 KB Output is correct
5 Correct 1 ms 2396 KB Output is correct
6 Correct 1 ms 2396 KB Output is correct
7 Correct 1 ms 2508 KB Output is correct
8 Correct 1 ms 2652 KB Output is correct
9 Correct 1 ms 2392 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2648 KB Output is correct
2 Correct 1 ms 2396 KB Output is correct
3 Correct 1 ms 2396 KB Output is correct
4 Correct 1 ms 2396 KB Output is correct
5 Correct 1 ms 2392 KB Output is correct
6 Correct 1 ms 2652 KB Output is correct
7 Correct 1 ms 2396 KB Output is correct
8 Correct 1 ms 2396 KB Output is correct
9 Correct 1 ms 2396 KB Output is correct
10 Correct 1 ms 2396 KB Output is correct
11 Correct 1 ms 2396 KB Output is correct
12 Correct 1 ms 2396 KB Output is correct
13 Correct 0 ms 2396 KB Output is correct
14 Correct 1 ms 2396 KB Output is correct
15 Correct 1 ms 2652 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 10 ms 2908 KB Output is correct
2 Correct 15 ms 2908 KB Output is correct
3 Correct 15 ms 2908 KB Output is correct
4 Correct 10 ms 3044 KB Output is correct
5 Correct 12 ms 3672 KB Output is correct
6 Correct 9 ms 2908 KB Output is correct
7 Correct 10 ms 3188 KB Output is correct
8 Correct 15 ms 3912 KB Output is correct
9 Correct 13 ms 3392 KB Output is correct
10 Correct 9 ms 2880 KB Output is correct
11 Correct 1 ms 2396 KB Output is correct
12 Correct 1 ms 2652 KB Output is correct
13 Correct 1 ms 2652 KB Output is correct
14 Correct 1 ms 2524 KB Output is correct
15 Correct 1 ms 2648 KB Output is correct
16 Correct 1 ms 2396 KB Output is correct
17 Correct 1 ms 2396 KB Output is correct
18 Correct 1 ms 2396 KB Output is correct
19 Correct 1 ms 2396 KB Output is correct
20 Correct 1 ms 2396 KB Output is correct
21 Correct 1 ms 2396 KB Output is correct
22 Correct 1 ms 2648 KB Output is correct
23 Correct 1 ms 2396 KB Output is correct
24 Correct 1 ms 2396 KB Output is correct
25 Correct 1 ms 2396 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 33 ms 4548 KB Output is correct
2 Correct 30 ms 4180 KB Output is correct
3 Correct 23 ms 3904 KB Output is correct
4 Correct 12 ms 2908 KB Output is correct
5 Correct 23 ms 4844 KB Output is correct
6 Correct 25 ms 4796 KB Output is correct
7 Correct 13 ms 3416 KB Output is correct
8 Correct 16 ms 3880 KB Output is correct
9 Correct 9 ms 2908 KB Output is correct
10 Correct 13 ms 3020 KB Output is correct
11 Correct 11 ms 2908 KB Output is correct
12 Correct 9 ms 2908 KB Output is correct
13 Correct 13 ms 3672 KB Output is correct
14 Correct 14 ms 2908 KB Output is correct
15 Correct 10 ms 3140 KB Output is correct
16 Correct 16 ms 3816 KB Output is correct
17 Correct 12 ms 3420 KB Output is correct
18 Correct 10 ms 2884 KB Output is correct
19 Correct 1 ms 2396 KB Output is correct
20 Correct 1 ms 2396 KB Output is correct
21 Correct 1 ms 2396 KB Output is correct
22 Correct 1 ms 2396 KB Output is correct
23 Correct 1 ms 2396 KB Output is correct
24 Correct 1 ms 2396 KB Output is correct
25 Correct 1 ms 2396 KB Output is correct
26 Correct 1 ms 2396 KB Output is correct
27 Correct 1 ms 2396 KB Output is correct
28 Correct 1 ms 2396 KB Output is correct
29 Correct 1 ms 2396 KB Output is correct
30 Correct 1 ms 2396 KB Output is correct
31 Correct 1 ms 2396 KB Output is correct
32 Correct 1 ms 2396 KB Output is correct
33 Correct 1 ms 2396 KB Output is correct