Submission #171682

# Submission time Handle Problem Language Result Execution time Memory
171682 2019-12-29T23:16:22 Z achibasadzishvili Rabbit Carrot (LMIO19_triusis) C++14
100 / 100
423 ms 94492 KB
#include<bits/stdc++.h>
#define ll long long
#define f first
#define s second
#define pb push_back
using namespace std;
ll n,k,a[200005],ans,dp[2000005];
struct node {
	ll mn;
	node *l,*r;
	node() : mn(n), l(NULL), r(NULL) {}
};

node *root = NULL;

void upd(node *&t, ll l, ll r, ll x, ll y) {
	if(t == NULL)t = new node();
	if(l == r){
		t -> mn = min(t -> mn , y);
		return;
	}
	
	ll m = (l + r) / 2;
	if(x <= m)upd(t->l, l, m, x, y);
    else upd(t->r, m + 1, r, x, y);
	
	t->mn = min((t -> l ? t -> l -> mn : n) , (t -> r ? t -> r -> mn : n));
}
ll cnt(node *t,ll l,ll r,ll x,ll y) {
	if(t){
		if(l >= x && r <= y)
			return t -> mn;
		if(l > y || r < x)return n;
		ll m = (l + r) / 2;
        ll k1,k2;
        k1 = cnt(t->l,l,m,x,y);
        k2 = cnt(t->r,m + 1,r,x,y);
        if(k2 < k1)k1 = k2;
		return k1;
	}
	return n;
}
int main(){
    ios::sync_with_stdio(false);
    cin >> n >> k;
    
    for(int i=1; i<=n; i++)
        cin >> a[i];
    upd(root , 1 , 3000000000 , 1000000000 , 0);
    dp[0] = 0;
    for(int i=1; i<=n; i++){
        ll g = a[i] - i * k + 1000000000;
        ll get = cnt(root , 1 , 3000000000 , g , 3000000000);
        dp[i] = get + i - 1;
        upd(root , 1 , 3000000000 , g , dp[i] - i);
    }
    ans = n;
    for(int i=n; i>=0; i--)
        ans = min(ans , dp[i] + n - i);
    
    cout << ans << '\n';
    
        
    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 2 ms 504 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 376 KB Output is correct
4 Correct 2 ms 376 KB Output is correct
5 Correct 2 ms 376 KB Output is correct
6 Correct 2 ms 376 KB Output is correct
7 Correct 2 ms 376 KB Output is correct
8 Correct 2 ms 376 KB Output is correct
9 Correct 2 ms 420 KB Output is correct
10 Correct 2 ms 376 KB Output is correct
11 Correct 2 ms 376 KB Output is correct
12 Correct 2 ms 376 KB Output is correct
13 Correct 2 ms 376 KB Output is correct
14 Correct 2 ms 376 KB Output is correct
15 Correct 2 ms 376 KB Output is correct
16 Correct 2 ms 376 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 380 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 376 KB Output is correct
4 Correct 6 ms 760 KB Output is correct
5 Correct 7 ms 1324 KB Output is correct
6 Correct 7 ms 760 KB Output is correct
7 Correct 9 ms 2424 KB Output is correct
8 Correct 9 ms 2680 KB Output is correct
9 Correct 7 ms 1400 KB Output is correct
10 Correct 9 ms 2168 KB Output is correct
11 Correct 5 ms 376 KB Output is correct
12 Correct 6 ms 504 KB Output is correct
13 Correct 7 ms 1272 KB Output is correct
14 Correct 8 ms 1400 KB Output is correct
15 Correct 6 ms 632 KB Output is correct
16 Correct 9 ms 2296 KB Output is correct
17 Correct 9 ms 2168 KB Output is correct
18 Correct 2 ms 504 KB Output is correct
19 Correct 2 ms 376 KB Output is correct
20 Correct 2 ms 376 KB Output is correct
21 Correct 2 ms 376 KB Output is correct
22 Correct 2 ms 376 KB Output is correct
23 Correct 2 ms 376 KB Output is correct
24 Correct 2 ms 376 KB Output is correct
25 Correct 2 ms 376 KB Output is correct
26 Correct 2 ms 420 KB Output is correct
27 Correct 2 ms 376 KB Output is correct
28 Correct 2 ms 376 KB Output is correct
29 Correct 2 ms 376 KB Output is correct
30 Correct 2 ms 376 KB Output is correct
31 Correct 2 ms 376 KB Output is correct
32 Correct 2 ms 376 KB Output is correct
33 Correct 2 ms 376 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 11 ms 3448 KB Output is correct
2 Correct 13 ms 3448 KB Output is correct
3 Correct 12 ms 3448 KB Output is correct
4 Correct 9 ms 2040 KB Output is correct
5 Correct 6 ms 504 KB Output is correct
6 Correct 6 ms 504 KB Output is correct
7 Correct 6 ms 632 KB Output is correct
8 Correct 5 ms 504 KB Output is correct
9 Correct 9 ms 2424 KB Output is correct
10 Correct 9 ms 2552 KB Output is correct
11 Correct 2 ms 380 KB Output is correct
12 Correct 2 ms 376 KB Output is correct
13 Correct 2 ms 376 KB Output is correct
14 Correct 6 ms 760 KB Output is correct
15 Correct 7 ms 1324 KB Output is correct
16 Correct 7 ms 760 KB Output is correct
17 Correct 9 ms 2424 KB Output is correct
18 Correct 9 ms 2680 KB Output is correct
19 Correct 7 ms 1400 KB Output is correct
20 Correct 9 ms 2168 KB Output is correct
21 Correct 5 ms 376 KB Output is correct
22 Correct 6 ms 504 KB Output is correct
23 Correct 7 ms 1272 KB Output is correct
24 Correct 8 ms 1400 KB Output is correct
25 Correct 6 ms 632 KB Output is correct
26 Correct 9 ms 2296 KB Output is correct
27 Correct 9 ms 2168 KB Output is correct
28 Correct 2 ms 504 KB Output is correct
29 Correct 2 ms 376 KB Output is correct
30 Correct 2 ms 376 KB Output is correct
31 Correct 2 ms 376 KB Output is correct
32 Correct 2 ms 376 KB Output is correct
33 Correct 2 ms 376 KB Output is correct
34 Correct 2 ms 376 KB Output is correct
35 Correct 2 ms 376 KB Output is correct
36 Correct 2 ms 420 KB Output is correct
37 Correct 2 ms 376 KB Output is correct
38 Correct 2 ms 376 KB Output is correct
39 Correct 2 ms 376 KB Output is correct
40 Correct 2 ms 376 KB Output is correct
41 Correct 2 ms 376 KB Output is correct
42 Correct 2 ms 376 KB Output is correct
43 Correct 2 ms 376 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 11 ms 3448 KB Output is correct
2 Correct 13 ms 3448 KB Output is correct
3 Correct 12 ms 3448 KB Output is correct
4 Correct 9 ms 2040 KB Output is correct
5 Correct 6 ms 504 KB Output is correct
6 Correct 6 ms 504 KB Output is correct
7 Correct 6 ms 632 KB Output is correct
8 Correct 5 ms 504 KB Output is correct
9 Correct 9 ms 2424 KB Output is correct
10 Correct 9 ms 2552 KB Output is correct
11 Correct 2 ms 380 KB Output is correct
12 Correct 2 ms 376 KB Output is correct
13 Correct 2 ms 376 KB Output is correct
14 Correct 6 ms 760 KB Output is correct
15 Correct 7 ms 1324 KB Output is correct
16 Correct 7 ms 760 KB Output is correct
17 Correct 9 ms 2424 KB Output is correct
18 Correct 9 ms 2680 KB Output is correct
19 Correct 7 ms 1400 KB Output is correct
20 Correct 9 ms 2168 KB Output is correct
21 Correct 5 ms 376 KB Output is correct
22 Correct 6 ms 504 KB Output is correct
23 Correct 7 ms 1272 KB Output is correct
24 Correct 8 ms 1400 KB Output is correct
25 Correct 6 ms 632 KB Output is correct
26 Correct 9 ms 2296 KB Output is correct
27 Correct 9 ms 2168 KB Output is correct
28 Correct 210 ms 37520 KB Output is correct
29 Correct 420 ms 90000 KB Output is correct
30 Correct 418 ms 94332 KB Output is correct
31 Correct 423 ms 94492 KB Output is correct
32 Correct 224 ms 39800 KB Output is correct
33 Correct 268 ms 68088 KB Output is correct
34 Correct 150 ms 5496 KB Output is correct
35 Correct 151 ms 5496 KB Output is correct
36 Correct 159 ms 10616 KB Output is correct
37 Correct 137 ms 4848 KB Output is correct
38 Correct 292 ms 81116 KB Output is correct
39 Correct 291 ms 80732 KB Output is correct
40 Correct 2 ms 504 KB Output is correct
41 Correct 2 ms 376 KB Output is correct
42 Correct 2 ms 376 KB Output is correct
43 Correct 2 ms 376 KB Output is correct
44 Correct 2 ms 376 KB Output is correct
45 Correct 2 ms 376 KB Output is correct
46 Correct 2 ms 376 KB Output is correct
47 Correct 2 ms 376 KB Output is correct
48 Correct 2 ms 420 KB Output is correct
49 Correct 2 ms 376 KB Output is correct
50 Correct 2 ms 376 KB Output is correct
51 Correct 2 ms 376 KB Output is correct
52 Correct 2 ms 376 KB Output is correct
53 Correct 2 ms 376 KB Output is correct
54 Correct 2 ms 376 KB Output is correct
55 Correct 2 ms 376 KB Output is correct