Submission #579610

# Submission time Handle Problem Language Result Execution time Memory
579610 2022-06-19T13:27:23 Z LOLOLO Rabbit Carrot (LMIO19_triusis) C++17
100 / 100
74 ms 5592 KB
#include <bits/stdc++.h>
#define ll long long
#define ull unsigned long long
#define pii pair<long long, long long>
#define st first
#define nd second
#define file "test"
using namespace std;
const long long oo = 1e18;
const long long N = 2e5 + 5;
 
int n, m, h[2*N], dp[2*N], bit[2*N], SIZE;
vector <int> compress;
 
int find(int x){
	int l = 0, r = compress.size() - 1, mid, ans = 0;
	while (l <= r){
		mid = l + r >> 1;
		if (compress[mid] >= x) 
			ans = mid + 1, r = mid - 1;
		else
			l = mid + 1;
	}
 
	return ans;
}
 
void upd(int idx, int val){
	while (idx > 0)
		bit[idx] = min(bit[idx], val),
		idx -= idx &-idx;
}
 
int get(int idx, int ans = 1e9){
	while (idx <= SIZE)
		ans = min(ans, bit[idx]),
		idx += idx & -idx;
	return ans;
}
int main()
{
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    // #ifndef ONLINE_JUDGE
    //     freopen(file".inp","r",stdin); freopen(file".out","w",stdout);
    // #endif
    
    cin >> n >> m;
 
    compress.push_back(0);
    for (int i = 1; i <= n; i ++){
        cin >> h[i];
        compress.push_back(h[i] - i*m);
    }
 
    compress.push_back(-(n + 1)*m);
    sort(compress.begin(), compress.end());
    SIZE = compress.size();
  	for (int i = 0; i <= n + 1000; i ++)
        dp[i] = bit[i] = 1e9;
 
    dp[0] = 0;
    upd(find(0), -1);
/*
    for (int i = 1; i <= n + 1; i ++){
        for (int j = i - 1; j >= 0; j --)
            if (h[j] - j*m >= h[i] - i*m)
                dp[i] = min(dp[i], dp[j] + i - j - 1);
        // cout << dp[i] << ' ';
    }
 
*/    
 
    for (int i = 1; i <= n + 1; i ++){
    	ll pos = find(h[i] - i*m), tmp = get(pos);
    	dp[i] = tmp + i;
 
    	upd(pos, dp[i] - i - 1);
    }
    cout << dp[n + 1];
    
 
    return 0;
}    
/**  /\_/\
    (= ._.)
    / >0  \>1 
  ________________________
 / Brainstorming section /
/=======================/
---
===
with two fixed point j, i you are allowed to change every pole between j, i (j < i)
-> could it be changed so that you can go from j->i
possible case: 
+ a[i] <= a[j]
+ h[j] + (i - j)*m >= h[i] <=> h[j] + i*m - j*m >= h[i] <=> h[j] - j*m >= h[i] - i*m
 
 
upd(h[i], dp[i] - i - 1)
get(h[j] - j*m)
 
===
**/
// Before submit: spot the visible bug by reading the code. 

Compilation message

triusis.cpp: In function 'int find(int)':
triusis.cpp:18:11: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   18 |   mid = l + r >> 1;
      |         ~~^~~
# Verdict Execution time Memory Grader output
1 Correct 0 ms 340 KB Output is correct
2 Correct 1 ms 328 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 328 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 1 ms 324 KB Output is correct
9 Correct 1 ms 328 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 1 ms 340 KB Output is correct
12 Correct 1 ms 340 KB Output is correct
13 Correct 1 ms 340 KB Output is correct
14 Correct 0 ms 340 KB Output is correct
15 Correct 1 ms 324 KB Output is correct
16 Correct 1 ms 340 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 340 KB Output is correct
2 Correct 1 ms 328 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 328 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 1 ms 324 KB Output is correct
9 Correct 1 ms 328 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 1 ms 340 KB Output is correct
12 Correct 1 ms 340 KB Output is correct
13 Correct 1 ms 340 KB Output is correct
14 Correct 0 ms 340 KB Output is correct
15 Correct 1 ms 324 KB Output is correct
16 Correct 1 ms 340 KB Output is correct
17 Correct 1 ms 340 KB Output is correct
18 Correct 1 ms 340 KB Output is correct
19 Correct 1 ms 320 KB Output is correct
20 Correct 1 ms 336 KB Output is correct
21 Correct 1 ms 468 KB Output is correct
22 Correct 2 ms 468 KB Output is correct
23 Correct 2 ms 464 KB Output is correct
24 Correct 2 ms 476 KB Output is correct
25 Correct 2 ms 468 KB Output is correct
26 Correct 2 ms 468 KB Output is correct
27 Correct 2 ms 468 KB Output is correct
28 Correct 1 ms 468 KB Output is correct
29 Correct 1 ms 468 KB Output is correct
30 Correct 1 ms 468 KB Output is correct
31 Correct 1 ms 396 KB Output is correct
32 Correct 2 ms 468 KB Output is correct
33 Correct 1 ms 468 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 1 ms 320 KB Output is correct
4 Correct 1 ms 336 KB Output is correct
5 Correct 1 ms 468 KB Output is correct
6 Correct 2 ms 468 KB Output is correct
7 Correct 2 ms 464 KB Output is correct
8 Correct 2 ms 476 KB Output is correct
9 Correct 2 ms 468 KB Output is correct
10 Correct 2 ms 468 KB Output is correct
11 Correct 2 ms 468 KB Output is correct
12 Correct 1 ms 468 KB Output is correct
13 Correct 1 ms 468 KB Output is correct
14 Correct 1 ms 468 KB Output is correct
15 Correct 1 ms 396 KB Output is correct
16 Correct 2 ms 468 KB Output is correct
17 Correct 1 ms 468 KB Output is correct
18 Correct 0 ms 340 KB Output is correct
19 Correct 1 ms 328 KB Output is correct
20 Correct 1 ms 340 KB Output is correct
21 Correct 1 ms 328 KB Output is correct
22 Correct 1 ms 340 KB Output is correct
23 Correct 1 ms 340 KB Output is correct
24 Correct 1 ms 340 KB Output is correct
25 Correct 1 ms 324 KB Output is correct
26 Correct 1 ms 328 KB Output is correct
27 Correct 1 ms 340 KB Output is correct
28 Correct 1 ms 340 KB Output is correct
29 Correct 1 ms 340 KB Output is correct
30 Correct 1 ms 340 KB Output is correct
31 Correct 0 ms 340 KB Output is correct
32 Correct 1 ms 324 KB Output is correct
33 Correct 1 ms 340 KB Output is correct
34 Correct 2 ms 468 KB Output is correct
35 Correct 2 ms 468 KB Output is correct
36 Correct 2 ms 404 KB Output is correct
37 Correct 2 ms 384 KB Output is correct
38 Correct 1 ms 472 KB Output is correct
39 Correct 2 ms 468 KB Output is correct
40 Correct 2 ms 468 KB Output is correct
41 Correct 2 ms 476 KB Output is correct
42 Correct 2 ms 468 KB Output is correct
43 Correct 1 ms 468 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 468 KB Output is correct
2 Correct 2 ms 468 KB Output is correct
3 Correct 2 ms 404 KB Output is correct
4 Correct 2 ms 384 KB Output is correct
5 Correct 1 ms 472 KB Output is correct
6 Correct 2 ms 468 KB Output is correct
7 Correct 2 ms 468 KB Output is correct
8 Correct 2 ms 476 KB Output is correct
9 Correct 2 ms 468 KB Output is correct
10 Correct 1 ms 468 KB Output is correct
11 Correct 1 ms 340 KB Output is correct
12 Correct 1 ms 340 KB Output is correct
13 Correct 1 ms 320 KB Output is correct
14 Correct 1 ms 336 KB Output is correct
15 Correct 1 ms 468 KB Output is correct
16 Correct 2 ms 468 KB Output is correct
17 Correct 2 ms 464 KB Output is correct
18 Correct 2 ms 476 KB Output is correct
19 Correct 2 ms 468 KB Output is correct
20 Correct 2 ms 468 KB Output is correct
21 Correct 2 ms 468 KB Output is correct
22 Correct 1 ms 468 KB Output is correct
23 Correct 1 ms 468 KB Output is correct
24 Correct 1 ms 468 KB Output is correct
25 Correct 1 ms 396 KB Output is correct
26 Correct 2 ms 468 KB Output is correct
27 Correct 1 ms 468 KB Output is correct
28 Correct 0 ms 340 KB Output is correct
29 Correct 1 ms 328 KB Output is correct
30 Correct 1 ms 340 KB Output is correct
31 Correct 1 ms 328 KB Output is correct
32 Correct 1 ms 340 KB Output is correct
33 Correct 1 ms 340 KB Output is correct
34 Correct 1 ms 340 KB Output is correct
35 Correct 1 ms 324 KB Output is correct
36 Correct 1 ms 328 KB Output is correct
37 Correct 1 ms 340 KB Output is correct
38 Correct 1 ms 340 KB Output is correct
39 Correct 1 ms 340 KB Output is correct
40 Correct 1 ms 340 KB Output is correct
41 Correct 0 ms 340 KB Output is correct
42 Correct 1 ms 324 KB Output is correct
43 Correct 1 ms 340 KB Output is correct
44 Correct 30 ms 3988 KB Output is correct
45 Correct 72 ms 5592 KB Output is correct
46 Correct 74 ms 5412 KB Output is correct
47 Correct 71 ms 5448 KB Output is correct
48 Correct 36 ms 4488 KB Output is correct
49 Correct 37 ms 4824 KB Output is correct
50 Correct 38 ms 5448 KB Output is correct
51 Correct 43 ms 5488 KB Output is correct
52 Correct 45 ms 4456 KB Output is correct
53 Correct 30 ms 4812 KB Output is correct
54 Correct 37 ms 4552 KB Output is correct
55 Correct 38 ms 4620 KB Output is correct