Submission #283265

# Submission time Handle Problem Language Result Execution time Memory
283265 2020-08-25T12:58:30 Z AlexLuchianov Martian DNA (BOI18_dna) C++14
100 / 100
176 ms 19832 KB
#include <iostream>
#include <vector>
#include <cassert>
#include <cmath>
#include <set>

using ll = long long;
#define MIN(a, b) (((a) < (b)) ? (a) : (b))
#define MAX(a, b) (((a) < (b)) ? (b) : (a))

int const nmax = 200000;
std::vector<int> g[1 + nmax];
int ptr[1 + nmax], v[1 + nmax];
int cond[1 + nmax];

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

  int n, k, q;
  std::cin >> n >> k >> q;
  for(int i = 1;i <= n; i++) {
    std::cin >> v[i];
    g[v[i]].push_back(i);
  }

  std::multiset<int> pq;
  for(int i = 1;i <= q;i++) {
    int val, cant;
    std::cin >> val >> cant;
    pq.insert(0);
    cond[val] = cant;
    if(g[val].size() < cant) {
      std::cout << "impossible";
      return 0;
    }
  }


  int result = n + 1;
  for(int i = 1;i <= n; i++) {
    ptr[v[i]]++;
    if(0 == cond[v[i]])
      continue;
    if(ptr[v[i]] == cond[v[i]]) {
      pq.erase(pq.find(0));
      pq.insert(g[v[i]][0]);
    } else if(cond[v[i]] < ptr[v[i]]) {
      pq.insert(g[v[i]][ptr[v[i]] - cond[v[i]] ]); 
      pq.erase(pq.find(g[v[i]][ptr[v[i]] - cond[v[i]] - 1]) );
    }
    if(0 < *pq.begin())
      result = std::min(result, i - *pq.begin() + 1);
  }

  if(result <= n)
    std::cout << result;
  else
    std::cout << "impossible";
  return 0;
}

Compilation message

dna.cpp: In function 'int main()':
dna.cpp:33:22: warning: comparison of integer expressions of different signedness: 'std::vector<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   33 |     if(g[val].size() < cant) {
      |        ~~~~~~~~~~~~~~^~~~~~
# Verdict Execution time Memory Grader output
1 Correct 3 ms 4992 KB Output is correct
2 Correct 4 ms 5120 KB Output is correct
3 Correct 4 ms 4992 KB Output is correct
4 Correct 4 ms 4992 KB Output is correct
5 Correct 4 ms 4992 KB Output is correct
6 Correct 4 ms 4992 KB Output is correct
7 Correct 4 ms 4992 KB Output is correct
8 Correct 3 ms 4992 KB Output is correct
9 Correct 4 ms 4992 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 5120 KB Output is correct
2 Correct 4 ms 5120 KB Output is correct
3 Correct 4 ms 5120 KB Output is correct
4 Correct 5 ms 5248 KB Output is correct
5 Correct 4 ms 5120 KB Output is correct
6 Correct 4 ms 5120 KB Output is correct
7 Correct 4 ms 4992 KB Output is correct
8 Correct 4 ms 4992 KB Output is correct
9 Correct 4 ms 4992 KB Output is correct
10 Correct 3 ms 4992 KB Output is correct
11 Correct 3 ms 4992 KB Output is correct
12 Correct 4 ms 4992 KB Output is correct
13 Correct 4 ms 4992 KB Output is correct
14 Correct 3 ms 4992 KB Output is correct
15 Correct 4 ms 4992 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 28 ms 7352 KB Output is correct
2 Correct 26 ms 7356 KB Output is correct
3 Correct 32 ms 7296 KB Output is correct
4 Correct 29 ms 7544 KB Output is correct
5 Correct 41 ms 9980 KB Output is correct
6 Correct 20 ms 7384 KB Output is correct
7 Correct 20 ms 7424 KB Output is correct
8 Correct 67 ms 14200 KB Output is correct
9 Correct 32 ms 8184 KB Output is correct
10 Correct 29 ms 7456 KB Output is correct
11 Correct 4 ms 5120 KB Output is correct
12 Correct 4 ms 5120 KB Output is correct
13 Correct 4 ms 5120 KB Output is correct
14 Correct 4 ms 5248 KB Output is correct
15 Correct 4 ms 5120 KB Output is correct
16 Correct 4 ms 5120 KB Output is correct
17 Correct 4 ms 4992 KB Output is correct
18 Correct 4 ms 4992 KB Output is correct
19 Correct 4 ms 4992 KB Output is correct
20 Correct 4 ms 4992 KB Output is correct
21 Correct 4 ms 4992 KB Output is correct
22 Correct 4 ms 4992 KB Output is correct
23 Correct 4 ms 4992 KB Output is correct
24 Correct 4 ms 4992 KB Output is correct
25 Correct 4 ms 4992 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 130 ms 14456 KB Output is correct
2 Correct 110 ms 12664 KB Output is correct
3 Correct 60 ms 10744 KB Output is correct
4 Correct 29 ms 7216 KB Output is correct
5 Correct 76 ms 10360 KB Output is correct
6 Correct 176 ms 19832 KB Output is correct
7 Correct 86 ms 8448 KB Output is correct
8 Correct 112 ms 9336 KB Output is correct
9 Correct 28 ms 7372 KB Output is correct
10 Correct 26 ms 7356 KB Output is correct
11 Correct 33 ms 7296 KB Output is correct
12 Correct 28 ms 7552 KB Output is correct
13 Correct 44 ms 9976 KB Output is correct
14 Correct 19 ms 7392 KB Output is correct
15 Correct 20 ms 7424 KB Output is correct
16 Correct 64 ms 14200 KB Output is correct
17 Correct 31 ms 8320 KB Output is correct
18 Correct 36 ms 7456 KB Output is correct
19 Correct 4 ms 5120 KB Output is correct
20 Correct 4 ms 5120 KB Output is correct
21 Correct 4 ms 5120 KB Output is correct
22 Correct 5 ms 5248 KB Output is correct
23 Correct 5 ms 5120 KB Output is correct
24 Correct 4 ms 5120 KB Output is correct
25 Correct 4 ms 4992 KB Output is correct
26 Correct 4 ms 4992 KB Output is correct
27 Correct 4 ms 4992 KB Output is correct
28 Correct 4 ms 4992 KB Output is correct
29 Correct 4 ms 4992 KB Output is correct
30 Correct 3 ms 4992 KB Output is correct
31 Correct 4 ms 4992 KB Output is correct
32 Correct 4 ms 5120 KB Output is correct
33 Correct 4 ms 4992 KB Output is correct