Submission #643511

# Submission time Handle Problem Language Result Execution time Memory
643511 2022-09-22T08:23:09 Z makanhulia Martian DNA (BOI18_dna) C++17
68 / 100
2000 ms 8936 KB
#include <bits/stdc++.h>
using namespace std;

const int N = 2e5 + 5;

int n, k, r, a[N], b[N], t[N], sum[N][10];

bool ok(int x, int y)
{  
  for(int i = 0; i < r; i++) {
    int s = sum[y][i] - (x == 0 ? 0 : sum[x - 1][i]);
    if(s < b[i]) {
      return 0;
    }
  }
  return 1;
}

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

  cin >> n >> k >> r;
  for(int i = 0; i < n; i++) cin >> a[i];
  for(int i = 0; i < r; i++) {
    int x, v;
    cin >> x >> v;
    b[i] = v;
    t[i] = x;
  }
  for(int i = 0; i < n; i++) {
    for(int j = 0; j < r; j++) {
      if(i > 0) sum[i][j] = sum[i - 1][j];
      sum[i][j] += (a[i] == t[j]);
    }
  }
  int ans = 1e9;
  for(int i = 0; i < n; i++) {
    int l = i, r = n - 1, z = -1;
    while(l <= r) {
      int mid = (l + r) / 2;
      if(ok(i, mid)) {
        r = mid - 1, z = mid;
      } else {
        l = mid + 1;
      }
    }

    if(z != -1) ans = min(ans, z - i + 1);
  }

  if(ans == 1e9) {
    cout << "impossible";
  } else {
    cout << ans;
  }
} 
# Verdict Execution time Memory Grader output
1 Correct 0 ms 340 KB Output is correct
2 Correct 0 ms 340 KB Output is correct
3 Correct 0 ms 340 KB Output is correct
4 Correct 0 ms 340 KB Output is correct
5 Correct 0 ms 340 KB Output is correct
6 Correct 0 ms 340 KB Output is correct
7 Correct 0 ms 340 KB Output is correct
8 Correct 0 ms 340 KB Output is correct
9 Correct 0 ms 340 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 468 KB Output is correct
2 Correct 1 ms 468 KB Output is correct
3 Correct 1 ms 468 KB Output is correct
4 Correct 1 ms 468 KB Output is correct
5 Correct 1 ms 468 KB Output is correct
6 Correct 2 ms 468 KB Output is correct
7 Correct 0 ms 340 KB Output is correct
8 Correct 0 ms 340 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
10 Correct 0 ms 340 KB Output is correct
11 Correct 1 ms 340 KB Output is correct
12 Correct 0 ms 340 KB Output is correct
13 Correct 0 ms 340 KB Output is correct
14 Correct 0 ms 340 KB Output is correct
15 Correct 0 ms 340 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 31 ms 8820 KB Output is correct
2 Correct 21 ms 8916 KB Output is correct
3 Correct 48 ms 8920 KB Output is correct
4 Correct 37 ms 8936 KB Output is correct
5 Correct 49 ms 8936 KB Output is correct
6 Correct 19 ms 8916 KB Output is correct
7 Correct 24 ms 8836 KB Output is correct
8 Correct 48 ms 8916 KB Output is correct
9 Correct 48 ms 8916 KB Output is correct
10 Correct 39 ms 8916 KB Output is correct
11 Correct 1 ms 468 KB Output is correct
12 Correct 1 ms 468 KB Output is correct
13 Correct 1 ms 468 KB Output is correct
14 Correct 1 ms 468 KB Output is correct
15 Correct 1 ms 468 KB Output is correct
16 Correct 1 ms 468 KB Output is correct
17 Correct 0 ms 340 KB Output is correct
18 Correct 0 ms 340 KB Output is correct
19 Correct 0 ms 340 KB Output is correct
20 Correct 0 ms 340 KB Output is correct
21 Correct 0 ms 340 KB Output is correct
22 Correct 0 ms 340 KB Output is correct
23 Correct 0 ms 340 KB Output is correct
24 Correct 1 ms 340 KB Output is correct
25 Correct 1 ms 340 KB Output is correct
# Verdict Execution time Memory Grader output
1 Execution timed out 2091 ms 2852 KB Time limit exceeded
2 Halted 0 ms 0 KB -