Submission #878322

# Submission time Handle Problem Language Result Execution time Memory
878322 2023-11-24T08:14:28 Z Erfan1386Y Martian DNA (BOI18_dna) C++17
100 / 100
45 ms 4576 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 1116 KB Output is correct
3 Correct 1 ms 1116 KB Output is correct
4 Correct 1 ms 1236 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 1112 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 1112 KB Output is correct
2 Correct 1 ms 1116 KB Output is correct
3 Correct 1 ms 1116 KB Output is correct
4 Correct 1 ms 1116 KB Output is correct
5 Correct 1 ms 1116 KB Output is correct
6 Correct 1 ms 1236 KB Output is correct
7 Correct 1 ms 1116 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 12 ms 2396 KB Output is correct
2 Correct 18 ms 2168 KB Output is correct
3 Correct 10 ms 2392 KB Output is correct
4 Correct 12 ms 2392 KB Output is correct
5 Correct 19 ms 3164 KB Output is correct
6 Correct 12 ms 2352 KB Output is correct
7 Correct 16 ms 2392 KB Output is correct
8 Correct 24 ms 3160 KB Output is correct
9 Correct 15 ms 2908 KB Output is correct
10 Correct 13 ms 2396 KB Output is correct
11 Correct 1 ms 1112 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 1244 KB Output is correct
15 Correct 1 ms 1116 KB Output is correct
16 Correct 1 ms 1116 KB Output is correct
17 Correct 1 ms 1112 KB Output is correct
18 Correct 1 ms 1116 KB Output is correct
19 Correct 1 ms 1228 KB Output is correct
20 Correct 1 ms 1116 KB Output is correct
21 Correct 1 ms 1116 KB Output is correct
22 Correct 1 ms 1112 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 1184 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 30 ms 3824 KB Output is correct
2 Correct 27 ms 3664 KB Output is correct
3 Correct 31 ms 3408 KB Output is correct
4 Correct 9 ms 2396 KB Output is correct
5 Correct 29 ms 4436 KB Output is correct
6 Correct 45 ms 4576 KB Output is correct
7 Correct 23 ms 2892 KB Output is correct
8 Correct 37 ms 3164 KB Output is correct
9 Correct 12 ms 2392 KB Output is correct
10 Correct 18 ms 2396 KB Output is correct
11 Correct 10 ms 2224 KB Output is correct
12 Correct 12 ms 2396 KB Output is correct
13 Correct 19 ms 3160 KB Output is correct
14 Correct 12 ms 2292 KB Output is correct
15 Correct 12 ms 2396 KB Output is correct
16 Correct 26 ms 3268 KB Output is correct
17 Correct 18 ms 2772 KB Output is correct
18 Correct 13 ms 2396 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 1116 KB Output is correct
22 Correct 1 ms 1116 KB Output is correct
23 Correct 2 ms 1116 KB Output is correct
24 Correct 1 ms 1116 KB Output is correct
25 Correct 1 ms 1112 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 1232 KB Output is correct
29 Correct 1 ms 1116 KB Output is correct
30 Correct 1 ms 1116 KB Output is correct
31 Correct 1 ms 1232 KB Output is correct
32 Correct 1 ms 1232 KB Output is correct
33 Correct 1 ms 1116 KB Output is correct