Submission #878267

# Submission time Handle Problem Language Result Execution time Memory
878267 2023-11-24T07:51:11 Z vjudge1 Martian DNA (BOI18_dna) C++17
100 / 100
47 ms 4688 KB
#include <bits/stdc++.h>
#define file_io freopen("input.txt", "r", stdin);freopen("output.txt", "w", stdout);
#define fast_io ios::sync_with_stdio(false);cin.tie(0);
#define what(x) cerr << #x << " is " << x << '\n';
#define kill(x) {cout << x << '\n'; return 0;}
#define all(x) (x).begin(), (x).end()
#define pii pair<int, int>
#define pll pair<ll, ll>
#define pb push_back
#define ll long long
#define F first
#define S second
const ll inf = 1e18, mod = 1e9 + 7, delta = 1e9 + 9, SQ = 450, P = 6065621;

using namespace std;

const ll N = 2e5 + 10, LG = 20;
int n, k, q, fine[N], a[N];

bool check (int x) {
  int cnt[N];
  memset(cnt, 0, sizeof cnt);
  int bad = 0;
  for (int i = 0; i < k; i++)
    bad += (fine[i] > 0);
  for (int i = 1; i <= x; i++) {
    cnt[a[i]]++;
    if (cnt[a[i]] == fine[a[i]]) {
      --bad;
    }
    if (bad == 0) return true;
  }
  int b = 1, e = x;
  while (e != n) {
    cnt[a[b]]--;
    if (cnt[a[b]] == fine[a[b]] - 1) ++bad;
    cnt[a[e + 1]]++;
    if (cnt[a[e + 1]] == fine[a[e + 1]]) --bad;
    ++b, ++e;
    if (!bad) return true;
  }
  return false;
}

int main() {
  fast_io;
  cin >> n >> k >> q;
  for (int i = 1; i <= n; i++) {
    cin >> a[i];
  }
  for (int i = 0; i < q; i++) {
    int x, y;
    cin >> x >> y;
    fine[x] += y;
  }
  int l = 1, r = n + 1;
  while (r - l) {
    int md = (r + l) >> 1;
    if (check(md)) r = md;
    else l = md + 1;
  }
  if (r > n) cout << "impossible\n";
  else cout << r << '\n';
  return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 1112 KB Output is correct
2 Correct 1 ms 1112 KB Output is correct
3 Correct 1 ms 1116 KB Output is correct
4 Correct 1 ms 1372 KB Output is correct
5 Correct 1 ms 1116 KB Output is correct
6 Correct 1 ms 1116 KB Output is correct
7 Correct 1 ms 1228 KB Output is correct
8 Correct 1 ms 1116 KB Output is correct
9 Correct 1 ms 1116 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 1116 KB Output is correct
2 Correct 1 ms 1116 KB Output is correct
3 Correct 2 ms 1116 KB Output is correct
4 Correct 2 ms 1116 KB Output is correct
5 Correct 1 ms 1116 KB Output is correct
6 Correct 1 ms 1116 KB Output is correct
7 Correct 1 ms 1244 KB Output is correct
8 Correct 1 ms 1116 KB Output is correct
9 Correct 1 ms 1116 KB Output is correct
10 Correct 1 ms 1116 KB Output is correct
11 Correct 1 ms 1116 KB Output is correct
12 Correct 1 ms 1116 KB Output is correct
13 Correct 1 ms 1116 KB Output is correct
14 Correct 1 ms 1116 KB Output is correct
15 Correct 1 ms 1116 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 13 ms 2392 KB Output is correct
2 Correct 18 ms 2412 KB Output is correct
3 Correct 10 ms 2424 KB Output is correct
4 Correct 12 ms 2428 KB Output is correct
5 Correct 19 ms 3168 KB Output is correct
6 Correct 12 ms 2200 KB Output is correct
7 Correct 13 ms 2396 KB Output is correct
8 Correct 24 ms 3160 KB Output is correct
9 Correct 15 ms 2908 KB Output is correct
10 Correct 15 ms 2332 KB Output is correct
11 Correct 1 ms 1116 KB Output is correct
12 Correct 1 ms 1112 KB Output is correct
13 Correct 1 ms 1116 KB Output is correct
14 Correct 1 ms 1116 KB Output is correct
15 Correct 1 ms 1116 KB Output is correct
16 Correct 1 ms 1112 KB Output is correct
17 Correct 1 ms 1116 KB Output is correct
18 Correct 1 ms 1116 KB Output is correct
19 Correct 1 ms 1116 KB Output is correct
20 Correct 1 ms 1116 KB Output is correct
21 Correct 1 ms 1112 KB Output is correct
22 Correct 1 ms 1232 KB Output is correct
23 Correct 1 ms 1116 KB Output is correct
24 Correct 1 ms 1116 KB Output is correct
25 Correct 1 ms 1116 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 30 ms 3928 KB Output is correct
2 Correct 41 ms 3832 KB Output is correct
3 Correct 32 ms 3420 KB Output is correct
4 Correct 9 ms 2396 KB Output is correct
5 Correct 47 ms 4436 KB Output is correct
6 Correct 40 ms 4688 KB Output is correct
7 Correct 18 ms 2904 KB Output is correct
8 Correct 27 ms 3164 KB Output is correct
9 Correct 15 ms 2484 KB Output is correct
10 Correct 19 ms 2396 KB Output is correct
11 Correct 11 ms 2396 KB Output is correct
12 Correct 13 ms 2396 KB Output is correct
13 Correct 20 ms 3052 KB Output is correct
14 Correct 19 ms 2392 KB Output is correct
15 Correct 17 ms 2380 KB Output is correct
16 Correct 29 ms 3164 KB Output is correct
17 Correct 19 ms 2892 KB Output is correct
18 Correct 15 ms 2392 KB Output is correct
19 Correct 1 ms 1236 KB Output is correct
20 Correct 1 ms 1116 KB Output is correct
21 Correct 1 ms 1252 KB Output is correct
22 Correct 2 ms 1116 KB Output is correct
23 Correct 1 ms 1248 KB Output is correct
24 Correct 1 ms 1116 KB Output is correct
25 Correct 1 ms 1232 KB Output is correct
26 Correct 1 ms 1116 KB Output is correct
27 Correct 1 ms 1116 KB Output is correct
28 Correct 1 ms 1228 KB Output is correct
29 Correct 1 ms 1116 KB Output is correct
30 Correct 1 ms 1232 KB Output is correct
31 Correct 1 ms 1116 KB Output is correct
32 Correct 1 ms 1116 KB Output is correct
33 Correct 1 ms 1116 KB Output is correct