Submission #299416

# Submission time Handle Problem Language Result Execution time Memory
299416 2020-09-14T21:27:03 Z Bruteforceman Rabbit Carrot (LMIO19_triusis) C++11
100 / 100
515 ms 18432 KB
#include <bits/stdc++.h>
using namespace std;
const int maxn = 2e5 + 10;
const int inf = 1e8;
int a[maxn], dp[maxn];
int idx = 0;
int t[maxn * 4];

void update(int x, int val, int c = 1, int b = 1, int e = idx) {
  if(b == e) {
    t[c] = val;
    return ;
  }
  int m = (b + e) >> 1;
  int l = c << 1;
  int r = l + 1;
  if(x <= m) update(x, val, l, b, m);
  else update(x, val, r, m + 1, e);
  t[c] = max(t[l], t[r]);
}
int query(int x, int y, int c = 1, int b = 1, int e = idx) {
  if(x <= b && e <= y) return t[c];
  if(y < b || e < x) return -inf;
  int m = (b + e) >> 1;
  int l = c << 1;
  int r = l + 1;
  return max(query(x, y, l, b, m), query(x, y, r, m + 1, e));
}

int main() {
  int n, k;
  scanf("%d %d", &n, &k);
  map <long long, int> comp;
  comp[0] = 0;
  for(int i = 1; i <= n; i++) {
    scanf("%d", &a[i]);
    comp[1LL * k * i - a[i]] = 0;
  }
  for(auto &i : comp) {
    i.second = ++idx;
  }
  for(int i = 1; i <= idx; i++) {
    update(i, -inf);
  }
  update(comp[0], 0);
  for(int i = 1; i <= n; i++) {
    dp[i] = 1 + query(1, comp[1LL * k * i - a[i]]);
    update(comp[1LL * k * i - a[i]], dp[i]);
  }
  cout << n - query(1, idx) << endl;
  return 0;
}

Compilation message

triusis.cpp: In function 'int main()':
triusis.cpp:32:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   32 |   scanf("%d %d", &n, &k);
      |   ~~~~~^~~~~~~~~~~~~~~~~
triusis.cpp:36:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   36 |     scanf("%d", &a[i]);
      |     ~~~~~^~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 1 ms 384 KB Output is correct
3 Correct 1 ms 384 KB Output is correct
4 Correct 1 ms 384 KB Output is correct
5 Correct 1 ms 384 KB Output is correct
6 Correct 1 ms 384 KB Output is correct
7 Correct 1 ms 384 KB Output is correct
8 Correct 1 ms 384 KB Output is correct
9 Correct 1 ms 384 KB Output is correct
10 Correct 1 ms 384 KB Output is correct
11 Correct 0 ms 384 KB Output is correct
12 Correct 1 ms 416 KB Output is correct
13 Correct 1 ms 384 KB Output is correct
14 Correct 0 ms 384 KB Output is correct
15 Correct 0 ms 384 KB Output is correct
16 Correct 1 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 384 KB Output is correct
2 Correct 1 ms 384 KB Output is correct
3 Correct 0 ms 384 KB Output is correct
4 Correct 4 ms 640 KB Output is correct
5 Correct 5 ms 768 KB Output is correct
6 Correct 5 ms 544 KB Output is correct
7 Correct 5 ms 768 KB Output is correct
8 Correct 5 ms 768 KB Output is correct
9 Correct 4 ms 768 KB Output is correct
10 Correct 5 ms 768 KB Output is correct
11 Correct 1 ms 384 KB Output is correct
12 Correct 1 ms 384 KB Output is correct
13 Correct 5 ms 768 KB Output is correct
14 Correct 5 ms 768 KB Output is correct
15 Correct 3 ms 512 KB Output is correct
16 Correct 4 ms 768 KB Output is correct
17 Correct 4 ms 768 KB Output is correct
18 Correct 1 ms 384 KB Output is correct
19 Correct 1 ms 384 KB Output is correct
20 Correct 1 ms 384 KB Output is correct
21 Correct 1 ms 384 KB Output is correct
22 Correct 1 ms 384 KB Output is correct
23 Correct 1 ms 384 KB Output is correct
24 Correct 1 ms 384 KB Output is correct
25 Correct 1 ms 384 KB Output is correct
26 Correct 1 ms 384 KB Output is correct
27 Correct 1 ms 384 KB Output is correct
28 Correct 0 ms 384 KB Output is correct
29 Correct 1 ms 416 KB Output is correct
30 Correct 1 ms 384 KB Output is correct
31 Correct 0 ms 384 KB Output is correct
32 Correct 0 ms 384 KB Output is correct
33 Correct 1 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 6 ms 768 KB Output is correct
2 Correct 6 ms 768 KB Output is correct
3 Correct 6 ms 768 KB Output is correct
4 Correct 6 ms 768 KB Output is correct
5 Correct 1 ms 384 KB Output is correct
6 Correct 1 ms 384 KB Output is correct
7 Correct 3 ms 640 KB Output is correct
8 Correct 1 ms 384 KB Output is correct
9 Correct 5 ms 768 KB Output is correct
10 Correct 5 ms 768 KB Output is correct
11 Correct 0 ms 384 KB Output is correct
12 Correct 1 ms 384 KB Output is correct
13 Correct 0 ms 384 KB Output is correct
14 Correct 4 ms 640 KB Output is correct
15 Correct 5 ms 768 KB Output is correct
16 Correct 5 ms 544 KB Output is correct
17 Correct 5 ms 768 KB Output is correct
18 Correct 5 ms 768 KB Output is correct
19 Correct 4 ms 768 KB Output is correct
20 Correct 5 ms 768 KB Output is correct
21 Correct 1 ms 384 KB Output is correct
22 Correct 1 ms 384 KB Output is correct
23 Correct 5 ms 768 KB Output is correct
24 Correct 5 ms 768 KB Output is correct
25 Correct 3 ms 512 KB Output is correct
26 Correct 4 ms 768 KB Output is correct
27 Correct 4 ms 768 KB Output is correct
28 Correct 1 ms 384 KB Output is correct
29 Correct 1 ms 384 KB Output is correct
30 Correct 1 ms 384 KB Output is correct
31 Correct 1 ms 384 KB Output is correct
32 Correct 1 ms 384 KB Output is correct
33 Correct 1 ms 384 KB Output is correct
34 Correct 1 ms 384 KB Output is correct
35 Correct 1 ms 384 KB Output is correct
36 Correct 1 ms 384 KB Output is correct
37 Correct 1 ms 384 KB Output is correct
38 Correct 0 ms 384 KB Output is correct
39 Correct 1 ms 416 KB Output is correct
40 Correct 1 ms 384 KB Output is correct
41 Correct 0 ms 384 KB Output is correct
42 Correct 0 ms 384 KB Output is correct
43 Correct 1 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 6 ms 768 KB Output is correct
2 Correct 6 ms 768 KB Output is correct
3 Correct 6 ms 768 KB Output is correct
4 Correct 6 ms 768 KB Output is correct
5 Correct 1 ms 384 KB Output is correct
6 Correct 1 ms 384 KB Output is correct
7 Correct 3 ms 640 KB Output is correct
8 Correct 1 ms 384 KB Output is correct
9 Correct 5 ms 768 KB Output is correct
10 Correct 5 ms 768 KB Output is correct
11 Correct 0 ms 384 KB Output is correct
12 Correct 1 ms 384 KB Output is correct
13 Correct 0 ms 384 KB Output is correct
14 Correct 4 ms 640 KB Output is correct
15 Correct 5 ms 768 KB Output is correct
16 Correct 5 ms 544 KB Output is correct
17 Correct 5 ms 768 KB Output is correct
18 Correct 5 ms 768 KB Output is correct
19 Correct 4 ms 768 KB Output is correct
20 Correct 5 ms 768 KB Output is correct
21 Correct 1 ms 384 KB Output is correct
22 Correct 1 ms 384 KB Output is correct
23 Correct 5 ms 768 KB Output is correct
24 Correct 5 ms 768 KB Output is correct
25 Correct 3 ms 512 KB Output is correct
26 Correct 4 ms 768 KB Output is correct
27 Correct 4 ms 768 KB Output is correct
28 Correct 226 ms 16632 KB Output is correct
29 Correct 515 ms 18424 KB Output is correct
30 Correct 468 ms 18432 KB Output is correct
31 Correct 479 ms 18424 KB Output is correct
32 Correct 196 ms 17088 KB Output is correct
33 Correct 218 ms 17656 KB Output is correct
34 Correct 46 ms 3832 KB Output is correct
35 Correct 45 ms 3832 KB Output is correct
36 Correct 174 ms 10104 KB Output is correct
37 Correct 36 ms 3192 KB Output is correct
38 Correct 214 ms 17528 KB Output is correct
39 Correct 211 ms 17400 KB Output is correct
40 Correct 1 ms 384 KB Output is correct
41 Correct 1 ms 384 KB Output is correct
42 Correct 1 ms 384 KB Output is correct
43 Correct 1 ms 384 KB Output is correct
44 Correct 1 ms 384 KB Output is correct
45 Correct 1 ms 384 KB Output is correct
46 Correct 1 ms 384 KB Output is correct
47 Correct 1 ms 384 KB Output is correct
48 Correct 1 ms 384 KB Output is correct
49 Correct 1 ms 384 KB Output is correct
50 Correct 0 ms 384 KB Output is correct
51 Correct 1 ms 416 KB Output is correct
52 Correct 1 ms 384 KB Output is correct
53 Correct 0 ms 384 KB Output is correct
54 Correct 0 ms 384 KB Output is correct
55 Correct 1 ms 384 KB Output is correct