Submission #380222

# Submission time Handle Problem Language Result Execution time Memory
380222 2021-03-20T15:05:16 Z peijar Growing Vegetables is Fun 4 (JOI21_ho_t1) C++17
100 / 100
28 ms 5740 KB
#include <bits/stdc++.h>
#define int long long
using namespace std;

signed main(void)
{
	ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);

	int nbFleurs;
	cin >> nbFleurs;
	vector<int> fleurs(nbFleurs);
	for (auto &v : fleurs)
		cin >> v;

	vector<int> costPrefix(nbFleurs), costSuffix(nbFleurs);
	costPrefix[0] = 0;
	for (int iFleurs = 1; iFleurs < nbFleurs; ++iFleurs) 
	{
		int nbNecessaires = max(0LL, fleurs[iFleurs-1] + 1 - fleurs[iFleurs]);
		costPrefix[iFleurs] = costPrefix[iFleurs-1] + nbNecessaires;
	}

	for (int iFleurs(nbFleurs-2); iFleurs >= 0; --iFleurs)
	{
		int nbNecessaires = max(0LL, fleurs[iFleurs+1] + 1 - fleurs[iFleurs]);
		costSuffix[iFleurs] = costSuffix[iFleurs+1] + nbNecessaires;
	}

	int sol(1e18);

	for (int iMax(0); iMax < nbFleurs; ++iMax)
	{
		int cout = max(costPrefix[iMax], costSuffix[iMax]);
		sol = min(sol, cout);
	}
	cout << sol << endl;
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 0 ms 364 KB Output is correct
3 Correct 0 ms 364 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
6 Correct 1 ms 364 KB Output is correct
7 Correct 1 ms 364 KB Output is correct
8 Correct 1 ms 364 KB Output is correct
9 Correct 1 ms 364 KB Output is correct
10 Correct 1 ms 364 KB Output is correct
11 Correct 1 ms 364 KB Output is correct
12 Correct 1 ms 364 KB Output is correct
13 Correct 1 ms 364 KB Output is correct
14 Correct 1 ms 364 KB Output is correct
15 Correct 1 ms 364 KB Output is correct
16 Correct 1 ms 364 KB Output is correct
17 Correct 1 ms 364 KB Output is correct
18 Correct 1 ms 364 KB Output is correct
19 Correct 1 ms 492 KB Output is correct
20 Correct 1 ms 364 KB Output is correct
21 Correct 1 ms 364 KB Output is correct
22 Correct 1 ms 364 KB Output is correct
23 Correct 1 ms 492 KB Output is correct
24 Correct 1 ms 364 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 0 ms 364 KB Output is correct
3 Correct 0 ms 364 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
6 Correct 1 ms 364 KB Output is correct
7 Correct 1 ms 364 KB Output is correct
8 Correct 1 ms 364 KB Output is correct
9 Correct 1 ms 364 KB Output is correct
10 Correct 1 ms 364 KB Output is correct
11 Correct 1 ms 364 KB Output is correct
12 Correct 1 ms 364 KB Output is correct
13 Correct 1 ms 364 KB Output is correct
14 Correct 1 ms 364 KB Output is correct
15 Correct 1 ms 364 KB Output is correct
16 Correct 1 ms 364 KB Output is correct
17 Correct 1 ms 364 KB Output is correct
18 Correct 1 ms 364 KB Output is correct
19 Correct 1 ms 492 KB Output is correct
20 Correct 1 ms 364 KB Output is correct
21 Correct 1 ms 364 KB Output is correct
22 Correct 1 ms 364 KB Output is correct
23 Correct 1 ms 492 KB Output is correct
24 Correct 1 ms 364 KB Output is correct
25 Correct 1 ms 364 KB Output is correct
26 Correct 26 ms 5740 KB Output is correct
27 Correct 26 ms 4972 KB Output is correct
28 Correct 26 ms 4972 KB Output is correct
29 Correct 25 ms 4972 KB Output is correct
30 Correct 24 ms 4972 KB Output is correct
31 Correct 27 ms 5032 KB Output is correct
32 Correct 26 ms 4972 KB Output is correct
33 Correct 26 ms 4972 KB Output is correct
34 Correct 26 ms 4972 KB Output is correct
35 Correct 21 ms 4972 KB Output is correct
36 Correct 21 ms 4972 KB Output is correct
37 Correct 21 ms 4972 KB Output is correct
38 Correct 25 ms 4972 KB Output is correct
39 Correct 26 ms 4972 KB Output is correct
40 Correct 26 ms 4972 KB Output is correct
41 Correct 28 ms 4972 KB Output is correct
42 Correct 24 ms 4972 KB Output is correct
43 Correct 26 ms 4972 KB Output is correct
44 Correct 25 ms 4972 KB Output is correct
45 Correct 26 ms 4972 KB Output is correct
46 Correct 25 ms 4972 KB Output is correct
47 Correct 26 ms 4972 KB Output is correct
48 Correct 27 ms 5032 KB Output is correct