# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
622507 |
2022-08-04T10:47:47 Z |
dozer |
Tortoise (CEOI21_tortoise) |
C++14 |
|
259 ms |
398684 KB |
#include <bits/stdc++.h>
using namespace std;
#define sp " "
#define endl "\n"
#define fastio() cin.tie(0), ios_base::sync_with_stdio(0)
#define pb push_back
#define fileio() freopen("input.txt", "r", stdin), freopen("output.txt", "w", stdout)
#define pii pair<int, int>
#define st first
#define nd second
#define N 5005
#define modulo 1000000007
#define int long long
int dp[N][N];
vector<int> pg;
int arr[N], n;
int f(int time, int ind)
{
if (time > 2 * (n - 1) || ind > n) return 0;
if (arr[ind] == -1) return dp[time][ind] = f(time + 1, ind + 1);
if (dp[time][ind] != -1) return dp[time][ind];
auto it = lower_bound(pg.begin(), pg.end(), ind);
int nxt = modulo, prv = - modulo;
if (it != pg.end()) nxt = *it;
if (it != pg.begin())
{
it--;
prv = *it;
}
int dist = min(ind - prv, nxt - ind);
int tmp = time, inc = 0, ans = 0;
while(tmp <= ind * 2 - 2 && inc < arr[ind])
{
if (nxt <= n)
{
for (int i = ind + 1; i <= nxt; i++)//for the last candy we buy, we can go to the next pg and come back to a forward shop
{
ans = max(ans, f(tmp + nxt - ind + nxt - i, i) + inc + 1);
}
}
ans = max(ans, f(tmp + 1, ind + 1) + inc); // we can just continue to the next place without buying more candies
ans = max(ans, inc + 1);//buy it and finish the process
tmp += 2 * dist;
inc++;
}
ans = max(ans, f(tmp + 1, ind + 1) + inc);
ans = max(ans, f(time + 1, ind + 1));
//cout<<time<<sp<<ind<<sp<<ans<<endl;
return dp[time][ind] = ans;
}
int32_t main()
{
fastio();
memset(dp, -1, sizeof(dp));
cin>>n;
int sum = 0;
for (int i = 1; i <= n; i++)
{
cin>>arr[i];
if (arr[i] == -1) pg.pb(i);
else sum += arr[i];
}
cout<<sum - f(0, 1)<<endl;
cerr<<"time taken: "<<(float)clock() / CLOCKS_PER_SEC<<" seconds\n";
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
80 ms |
196340 KB |
Output is correct |
2 |
Correct |
71 ms |
196276 KB |
Output is correct |
3 |
Correct |
74 ms |
196348 KB |
Output is correct |
4 |
Correct |
84 ms |
196292 KB |
Output is correct |
5 |
Correct |
75 ms |
196388 KB |
Output is correct |
6 |
Correct |
72 ms |
196412 KB |
Output is correct |
7 |
Correct |
72 ms |
196272 KB |
Output is correct |
8 |
Correct |
72 ms |
196380 KB |
Output is correct |
9 |
Correct |
89 ms |
196388 KB |
Output is correct |
10 |
Correct |
75 ms |
196340 KB |
Output is correct |
11 |
Correct |
72 ms |
196300 KB |
Output is correct |
12 |
Correct |
73 ms |
196336 KB |
Output is correct |
13 |
Correct |
73 ms |
196308 KB |
Output is correct |
14 |
Correct |
73 ms |
196300 KB |
Output is correct |
15 |
Correct |
74 ms |
196304 KB |
Output is correct |
16 |
Correct |
71 ms |
196332 KB |
Output is correct |
17 |
Correct |
71 ms |
196360 KB |
Output is correct |
18 |
Correct |
71 ms |
196308 KB |
Output is correct |
19 |
Correct |
73 ms |
196284 KB |
Output is correct |
20 |
Correct |
73 ms |
196284 KB |
Output is correct |
21 |
Correct |
83 ms |
196340 KB |
Output is correct |
22 |
Correct |
84 ms |
196280 KB |
Output is correct |
23 |
Correct |
72 ms |
196280 KB |
Output is correct |
24 |
Correct |
71 ms |
196336 KB |
Output is correct |
25 |
Correct |
80 ms |
196324 KB |
Output is correct |
26 |
Correct |
80 ms |
196292 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
80 ms |
196340 KB |
Output is correct |
2 |
Correct |
71 ms |
196276 KB |
Output is correct |
3 |
Correct |
74 ms |
196348 KB |
Output is correct |
4 |
Correct |
84 ms |
196292 KB |
Output is correct |
5 |
Correct |
75 ms |
196388 KB |
Output is correct |
6 |
Correct |
72 ms |
196412 KB |
Output is correct |
7 |
Correct |
72 ms |
196272 KB |
Output is correct |
8 |
Correct |
72 ms |
196380 KB |
Output is correct |
9 |
Correct |
89 ms |
196388 KB |
Output is correct |
10 |
Correct |
75 ms |
196340 KB |
Output is correct |
11 |
Correct |
72 ms |
196300 KB |
Output is correct |
12 |
Correct |
73 ms |
196336 KB |
Output is correct |
13 |
Correct |
73 ms |
196308 KB |
Output is correct |
14 |
Correct |
73 ms |
196300 KB |
Output is correct |
15 |
Correct |
74 ms |
196304 KB |
Output is correct |
16 |
Correct |
71 ms |
196332 KB |
Output is correct |
17 |
Correct |
71 ms |
196360 KB |
Output is correct |
18 |
Correct |
71 ms |
196308 KB |
Output is correct |
19 |
Correct |
73 ms |
196284 KB |
Output is correct |
20 |
Correct |
73 ms |
196284 KB |
Output is correct |
21 |
Correct |
83 ms |
196340 KB |
Output is correct |
22 |
Correct |
84 ms |
196280 KB |
Output is correct |
23 |
Correct |
72 ms |
196280 KB |
Output is correct |
24 |
Correct |
71 ms |
196336 KB |
Output is correct |
25 |
Correct |
80 ms |
196324 KB |
Output is correct |
26 |
Correct |
80 ms |
196292 KB |
Output is correct |
27 |
Correct |
85 ms |
196332 KB |
Output is correct |
28 |
Correct |
87 ms |
196300 KB |
Output is correct |
29 |
Correct |
83 ms |
196416 KB |
Output is correct |
30 |
Correct |
72 ms |
196300 KB |
Output is correct |
31 |
Correct |
72 ms |
196312 KB |
Output is correct |
32 |
Correct |
90 ms |
196372 KB |
Output is correct |
33 |
Correct |
76 ms |
196420 KB |
Output is correct |
34 |
Correct |
80 ms |
196316 KB |
Output is correct |
35 |
Correct |
75 ms |
196396 KB |
Output is correct |
36 |
Correct |
77 ms |
196428 KB |
Output is correct |
37 |
Correct |
71 ms |
196332 KB |
Output is correct |
38 |
Correct |
79 ms |
196348 KB |
Output is correct |
39 |
Correct |
83 ms |
196320 KB |
Output is correct |
40 |
Correct |
74 ms |
196312 KB |
Output is correct |
41 |
Correct |
73 ms |
196312 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
80 ms |
196340 KB |
Output is correct |
2 |
Correct |
71 ms |
196276 KB |
Output is correct |
3 |
Correct |
74 ms |
196348 KB |
Output is correct |
4 |
Correct |
84 ms |
196292 KB |
Output is correct |
5 |
Correct |
75 ms |
196388 KB |
Output is correct |
6 |
Correct |
72 ms |
196412 KB |
Output is correct |
7 |
Correct |
72 ms |
196272 KB |
Output is correct |
8 |
Correct |
72 ms |
196380 KB |
Output is correct |
9 |
Correct |
89 ms |
196388 KB |
Output is correct |
10 |
Correct |
75 ms |
196340 KB |
Output is correct |
11 |
Correct |
72 ms |
196300 KB |
Output is correct |
12 |
Correct |
73 ms |
196336 KB |
Output is correct |
13 |
Correct |
73 ms |
196308 KB |
Output is correct |
14 |
Correct |
73 ms |
196300 KB |
Output is correct |
15 |
Correct |
74 ms |
196304 KB |
Output is correct |
16 |
Correct |
71 ms |
196332 KB |
Output is correct |
17 |
Correct |
71 ms |
196360 KB |
Output is correct |
18 |
Correct |
71 ms |
196308 KB |
Output is correct |
19 |
Correct |
73 ms |
196284 KB |
Output is correct |
20 |
Correct |
73 ms |
196284 KB |
Output is correct |
21 |
Correct |
83 ms |
196340 KB |
Output is correct |
22 |
Correct |
84 ms |
196280 KB |
Output is correct |
23 |
Correct |
72 ms |
196280 KB |
Output is correct |
24 |
Correct |
71 ms |
196336 KB |
Output is correct |
25 |
Correct |
80 ms |
196324 KB |
Output is correct |
26 |
Correct |
80 ms |
196292 KB |
Output is correct |
27 |
Correct |
85 ms |
196332 KB |
Output is correct |
28 |
Correct |
87 ms |
196300 KB |
Output is correct |
29 |
Correct |
83 ms |
196416 KB |
Output is correct |
30 |
Correct |
72 ms |
196300 KB |
Output is correct |
31 |
Correct |
72 ms |
196312 KB |
Output is correct |
32 |
Correct |
90 ms |
196372 KB |
Output is correct |
33 |
Correct |
76 ms |
196420 KB |
Output is correct |
34 |
Correct |
80 ms |
196316 KB |
Output is correct |
35 |
Correct |
75 ms |
196396 KB |
Output is correct |
36 |
Correct |
77 ms |
196428 KB |
Output is correct |
37 |
Correct |
71 ms |
196332 KB |
Output is correct |
38 |
Correct |
79 ms |
196348 KB |
Output is correct |
39 |
Correct |
83 ms |
196320 KB |
Output is correct |
40 |
Correct |
74 ms |
196312 KB |
Output is correct |
41 |
Correct |
73 ms |
196312 KB |
Output is correct |
42 |
Correct |
76 ms |
196300 KB |
Output is correct |
43 |
Correct |
87 ms |
196356 KB |
Output is correct |
44 |
Correct |
77 ms |
196340 KB |
Output is correct |
45 |
Correct |
73 ms |
196392 KB |
Output is correct |
46 |
Correct |
73 ms |
196336 KB |
Output is correct |
47 |
Correct |
78 ms |
196336 KB |
Output is correct |
48 |
Correct |
78 ms |
196348 KB |
Output is correct |
49 |
Correct |
79 ms |
196376 KB |
Output is correct |
50 |
Correct |
82 ms |
196400 KB |
Output is correct |
51 |
Correct |
88 ms |
196552 KB |
Output is correct |
52 |
Correct |
76 ms |
196348 KB |
Output is correct |
53 |
Correct |
85 ms |
196420 KB |
Output is correct |
54 |
Correct |
87 ms |
196404 KB |
Output is correct |
55 |
Correct |
81 ms |
196360 KB |
Output is correct |
56 |
Correct |
79 ms |
196404 KB |
Output is correct |
57 |
Correct |
78 ms |
196320 KB |
Output is correct |
58 |
Correct |
85 ms |
196428 KB |
Output is correct |
59 |
Correct |
75 ms |
196352 KB |
Output is correct |
60 |
Correct |
84 ms |
196376 KB |
Output is correct |
61 |
Correct |
77 ms |
196508 KB |
Output is correct |
62 |
Correct |
90 ms |
196380 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
80 ms |
196340 KB |
Output is correct |
2 |
Correct |
71 ms |
196276 KB |
Output is correct |
3 |
Correct |
74 ms |
196348 KB |
Output is correct |
4 |
Correct |
84 ms |
196292 KB |
Output is correct |
5 |
Correct |
75 ms |
196388 KB |
Output is correct |
6 |
Correct |
72 ms |
196412 KB |
Output is correct |
7 |
Correct |
72 ms |
196272 KB |
Output is correct |
8 |
Correct |
72 ms |
196380 KB |
Output is correct |
9 |
Correct |
89 ms |
196388 KB |
Output is correct |
10 |
Correct |
75 ms |
196340 KB |
Output is correct |
11 |
Correct |
72 ms |
196300 KB |
Output is correct |
12 |
Correct |
73 ms |
196336 KB |
Output is correct |
13 |
Correct |
73 ms |
196308 KB |
Output is correct |
14 |
Correct |
73 ms |
196300 KB |
Output is correct |
15 |
Correct |
74 ms |
196304 KB |
Output is correct |
16 |
Correct |
71 ms |
196332 KB |
Output is correct |
17 |
Correct |
71 ms |
196360 KB |
Output is correct |
18 |
Correct |
71 ms |
196308 KB |
Output is correct |
19 |
Correct |
73 ms |
196284 KB |
Output is correct |
20 |
Correct |
73 ms |
196284 KB |
Output is correct |
21 |
Correct |
83 ms |
196340 KB |
Output is correct |
22 |
Correct |
84 ms |
196280 KB |
Output is correct |
23 |
Correct |
72 ms |
196280 KB |
Output is correct |
24 |
Correct |
71 ms |
196336 KB |
Output is correct |
25 |
Correct |
80 ms |
196324 KB |
Output is correct |
26 |
Correct |
80 ms |
196292 KB |
Output is correct |
27 |
Correct |
85 ms |
196332 KB |
Output is correct |
28 |
Correct |
87 ms |
196300 KB |
Output is correct |
29 |
Correct |
83 ms |
196416 KB |
Output is correct |
30 |
Correct |
72 ms |
196300 KB |
Output is correct |
31 |
Correct |
72 ms |
196312 KB |
Output is correct |
32 |
Correct |
90 ms |
196372 KB |
Output is correct |
33 |
Correct |
76 ms |
196420 KB |
Output is correct |
34 |
Correct |
80 ms |
196316 KB |
Output is correct |
35 |
Correct |
75 ms |
196396 KB |
Output is correct |
36 |
Correct |
77 ms |
196428 KB |
Output is correct |
37 |
Correct |
71 ms |
196332 KB |
Output is correct |
38 |
Correct |
79 ms |
196348 KB |
Output is correct |
39 |
Correct |
83 ms |
196320 KB |
Output is correct |
40 |
Correct |
74 ms |
196312 KB |
Output is correct |
41 |
Correct |
73 ms |
196312 KB |
Output is correct |
42 |
Correct |
76 ms |
196300 KB |
Output is correct |
43 |
Correct |
87 ms |
196356 KB |
Output is correct |
44 |
Correct |
77 ms |
196340 KB |
Output is correct |
45 |
Correct |
73 ms |
196392 KB |
Output is correct |
46 |
Correct |
73 ms |
196336 KB |
Output is correct |
47 |
Correct |
78 ms |
196336 KB |
Output is correct |
48 |
Correct |
78 ms |
196348 KB |
Output is correct |
49 |
Correct |
79 ms |
196376 KB |
Output is correct |
50 |
Correct |
82 ms |
196400 KB |
Output is correct |
51 |
Correct |
88 ms |
196552 KB |
Output is correct |
52 |
Correct |
76 ms |
196348 KB |
Output is correct |
53 |
Correct |
85 ms |
196420 KB |
Output is correct |
54 |
Correct |
87 ms |
196404 KB |
Output is correct |
55 |
Correct |
81 ms |
196360 KB |
Output is correct |
56 |
Correct |
79 ms |
196404 KB |
Output is correct |
57 |
Correct |
78 ms |
196320 KB |
Output is correct |
58 |
Correct |
85 ms |
196428 KB |
Output is correct |
59 |
Correct |
75 ms |
196352 KB |
Output is correct |
60 |
Correct |
84 ms |
196376 KB |
Output is correct |
61 |
Correct |
77 ms |
196508 KB |
Output is correct |
62 |
Correct |
90 ms |
196380 KB |
Output is correct |
63 |
Runtime error |
259 ms |
398684 KB |
Execution killed with signal 11 |
64 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
80 ms |
196340 KB |
Output is correct |
2 |
Correct |
71 ms |
196276 KB |
Output is correct |
3 |
Correct |
74 ms |
196348 KB |
Output is correct |
4 |
Correct |
84 ms |
196292 KB |
Output is correct |
5 |
Correct |
75 ms |
196388 KB |
Output is correct |
6 |
Correct |
72 ms |
196412 KB |
Output is correct |
7 |
Correct |
72 ms |
196272 KB |
Output is correct |
8 |
Correct |
72 ms |
196380 KB |
Output is correct |
9 |
Correct |
89 ms |
196388 KB |
Output is correct |
10 |
Correct |
75 ms |
196340 KB |
Output is correct |
11 |
Correct |
72 ms |
196300 KB |
Output is correct |
12 |
Correct |
73 ms |
196336 KB |
Output is correct |
13 |
Correct |
73 ms |
196308 KB |
Output is correct |
14 |
Correct |
73 ms |
196300 KB |
Output is correct |
15 |
Correct |
74 ms |
196304 KB |
Output is correct |
16 |
Correct |
71 ms |
196332 KB |
Output is correct |
17 |
Correct |
71 ms |
196360 KB |
Output is correct |
18 |
Correct |
71 ms |
196308 KB |
Output is correct |
19 |
Correct |
73 ms |
196284 KB |
Output is correct |
20 |
Correct |
73 ms |
196284 KB |
Output is correct |
21 |
Correct |
83 ms |
196340 KB |
Output is correct |
22 |
Correct |
84 ms |
196280 KB |
Output is correct |
23 |
Correct |
72 ms |
196280 KB |
Output is correct |
24 |
Correct |
71 ms |
196336 KB |
Output is correct |
25 |
Correct |
80 ms |
196324 KB |
Output is correct |
26 |
Correct |
80 ms |
196292 KB |
Output is correct |
27 |
Correct |
85 ms |
196332 KB |
Output is correct |
28 |
Correct |
87 ms |
196300 KB |
Output is correct |
29 |
Correct |
83 ms |
196416 KB |
Output is correct |
30 |
Correct |
72 ms |
196300 KB |
Output is correct |
31 |
Correct |
72 ms |
196312 KB |
Output is correct |
32 |
Correct |
90 ms |
196372 KB |
Output is correct |
33 |
Correct |
76 ms |
196420 KB |
Output is correct |
34 |
Correct |
80 ms |
196316 KB |
Output is correct |
35 |
Correct |
75 ms |
196396 KB |
Output is correct |
36 |
Correct |
77 ms |
196428 KB |
Output is correct |
37 |
Correct |
71 ms |
196332 KB |
Output is correct |
38 |
Correct |
79 ms |
196348 KB |
Output is correct |
39 |
Correct |
83 ms |
196320 KB |
Output is correct |
40 |
Correct |
74 ms |
196312 KB |
Output is correct |
41 |
Correct |
73 ms |
196312 KB |
Output is correct |
42 |
Correct |
76 ms |
196300 KB |
Output is correct |
43 |
Correct |
87 ms |
196356 KB |
Output is correct |
44 |
Correct |
77 ms |
196340 KB |
Output is correct |
45 |
Correct |
73 ms |
196392 KB |
Output is correct |
46 |
Correct |
73 ms |
196336 KB |
Output is correct |
47 |
Correct |
78 ms |
196336 KB |
Output is correct |
48 |
Correct |
78 ms |
196348 KB |
Output is correct |
49 |
Correct |
79 ms |
196376 KB |
Output is correct |
50 |
Correct |
82 ms |
196400 KB |
Output is correct |
51 |
Correct |
88 ms |
196552 KB |
Output is correct |
52 |
Correct |
76 ms |
196348 KB |
Output is correct |
53 |
Correct |
85 ms |
196420 KB |
Output is correct |
54 |
Correct |
87 ms |
196404 KB |
Output is correct |
55 |
Correct |
81 ms |
196360 KB |
Output is correct |
56 |
Correct |
79 ms |
196404 KB |
Output is correct |
57 |
Correct |
78 ms |
196320 KB |
Output is correct |
58 |
Correct |
85 ms |
196428 KB |
Output is correct |
59 |
Correct |
75 ms |
196352 KB |
Output is correct |
60 |
Correct |
84 ms |
196376 KB |
Output is correct |
61 |
Correct |
77 ms |
196508 KB |
Output is correct |
62 |
Correct |
90 ms |
196380 KB |
Output is correct |
63 |
Runtime error |
259 ms |
398684 KB |
Execution killed with signal 11 |
64 |
Halted |
0 ms |
0 KB |
- |