Submission #1005961

# Submission time Handle Problem Language Result Execution time Memory
1005961 2024-06-23T09:13:45 Z pudelos Martian DNA (BOI18_dna) C++17
100 / 100
111 ms 9300 KB
#include <bits/stdc++.h>
using namespace std;
#define FOR(i, a, b) for(int i=a; i<=b; ++i)
#define ll long long
#define sz(A) (int)(A.size())
#define pb push_back
#define eb emplace_back
#define V vector
#define pi pair<int, int>
#define f first
#define s second
const int inf=1e9;

int res=inf;
int n, k, r;
V<int> A, stan, needed;

int main() {
  cin.tie(0) -> ios_base::sync_with_stdio(0);
  cin >> n >> k >> r;
  A.resize(n+1);
  needed.resize(k+1);
  stan.resize(k+1);
  FOR(i, 1, n) cin >> A[i];
  set<pi> secik;
  int co, ile;
  FOR(i, 1, r) {
    cin >> co >> ile;
    if(ile<=0) continue;
    needed[co]=ile;
    secik.insert({co, ile});
  }

  // int l=1;
  int r=1;
  stan[A[1]]++;
  auto it = secik.find({A[1], needed[A[1]]});
  if(it!=secik.end()) {
    pi dane = *it;
    dane.s--;
    secik.erase(it);
    if(dane.s!=0) secik.insert(dane);
  }

  while(!secik.empty() && r<n) {
    ++r;
    auto it = secik.find({A[r], needed[A[r]]-stan[A[r]]});
    stan[A[r]]++;
    if(it!=secik.end()) {
      pi dane = *it;
      dane.s--;
      secik.erase(it);
      if(dane.s!=0) secik.insert(dane);
    }
  }

  if(!secik.empty()) {
    cout << "impossible\n";
    return 0;
  }

  res=min(res, r);
  int l=1;
  while(l<=n) {
    stan[A[l]]--;
    while(r<n && stan[A[l]]<needed[A[l]]) {
      ++r;
      stan[A[r]]++;
    }
    if(stan[A[l]]<needed[A[l]]) break;
    ++l;
    res=min(res, r-l+1);
  }

  cout << res << '\n';
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 1 ms 456 KB Output is correct
4 Correct 1 ms 432 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 12 ms 1620 KB Output is correct
2 Correct 10 ms 1628 KB Output is correct
3 Correct 9 ms 1628 KB Output is correct
4 Correct 11 ms 1628 KB Output is correct
5 Correct 12 ms 3028 KB Output is correct
6 Correct 21 ms 1432 KB Output is correct
7 Correct 9 ms 1628 KB Output is correct
8 Correct 15 ms 4088 KB Output is correct
9 Correct 11 ms 2068 KB Output is correct
10 Correct 13 ms 1628 KB Output is correct
11 Correct 1 ms 348 KB Output is correct
12 Correct 0 ms 476 KB Output is correct
13 Correct 1 ms 512 KB Output is correct
14 Correct 0 ms 356 KB Output is correct
15 Correct 1 ms 360 KB Output is correct
16 Correct 0 ms 360 KB Output is correct
17 Correct 1 ms 360 KB Output is correct
18 Correct 0 ms 360 KB Output is correct
19 Correct 0 ms 360 KB Output is correct
20 Correct 0 ms 360 KB Output is correct
21 Correct 0 ms 356 KB Output is correct
22 Correct 0 ms 360 KB Output is correct
23 Correct 0 ms 356 KB Output is correct
24 Correct 0 ms 356 KB Output is correct
25 Correct 0 ms 356 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 57 ms 7244 KB Output is correct
2 Correct 43 ms 5976 KB Output is correct
3 Correct 27 ms 3940 KB Output is correct
4 Correct 8 ms 1628 KB Output is correct
5 Correct 111 ms 7776 KB Output is correct
6 Correct 90 ms 9300 KB Output is correct
7 Correct 35 ms 2648 KB Output is correct
8 Correct 35 ms 3160 KB Output is correct
9 Correct 12 ms 1628 KB Output is correct
10 Correct 10 ms 1496 KB Output is correct
11 Correct 9 ms 1628 KB Output is correct
12 Correct 11 ms 1628 KB Output is correct
13 Correct 13 ms 2908 KB Output is correct
14 Correct 21 ms 1628 KB Output is correct
15 Correct 9 ms 1628 KB Output is correct
16 Correct 15 ms 3964 KB Output is correct
17 Correct 11 ms 2068 KB Output is correct
18 Correct 13 ms 1628 KB Output is correct
19 Correct 1 ms 348 KB Output is correct
20 Correct 0 ms 348 KB Output is correct
21 Correct 1 ms 348 KB Output is correct
22 Correct 1 ms 348 KB Output is correct
23 Correct 1 ms 504 KB Output is correct
24 Correct 0 ms 348 KB Output is correct
25 Correct 0 ms 348 KB Output is correct
26 Correct 0 ms 348 KB Output is correct
27 Correct 0 ms 456 KB Output is correct
28 Correct 1 ms 348 KB Output is correct
29 Correct 0 ms 348 KB Output is correct
30 Correct 0 ms 348 KB Output is correct
31 Correct 0 ms 348 KB Output is correct
32 Correct 0 ms 348 KB Output is correct
33 Correct 0 ms 348 KB Output is correct