답안 #1027116

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1027116 2024-07-18T22:07:11 Z aykhn Growing Vegetables is Fun 4 (JOI21_ho_t1) C++17
100 / 100
17 ms 7256 KB
#include <bits/stdc++.h>
 
using namespace std;

#define inf 0x3F3F3F3F3F3F3F3F
#define int long long

const int MXN = 2e5 + 5;

int n;
int a[MXN];
int p[MXN], s[MXN];

signed main()
{
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cin >> n;
	for (int i = 1; i <= n; i++) cin >> a[i];
	a[0] = -inf, a[n + 1] = -inf;
	for (int i = 1; i <= n; i++) p[i] = p[i - 1] + max(0LL, a[i - 1] + 1 - a[i]);
	for (int i = n; i >= 1; i--) s[i] = s[i + 1] + max(0LL, a[i + 1] + 1 - a[i]);
	int res = inf;
	for (int i = 1; i <= n; i++) res = min(res, max(p[i - 1], s[i + 1]) + max(0LL, max(a[i - 1], a[i + 1]) + 1 - a[i]));
	cout << res << '\n';
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 2392 KB Output is correct
2 Correct 0 ms 2396 KB Output is correct
3 Correct 1 ms 2396 KB Output is correct
4 Correct 1 ms 2396 KB Output is correct
5 Correct 1 ms 2396 KB Output is correct
6 Correct 1 ms 2396 KB Output is correct
7 Correct 0 ms 2396 KB Output is correct
8 Correct 0 ms 2396 KB Output is correct
9 Correct 1 ms 2396 KB Output is correct
10 Correct 0 ms 2396 KB Output is correct
11 Correct 0 ms 2396 KB Output is correct
12 Correct 0 ms 2396 KB Output is correct
13 Correct 0 ms 2520 KB Output is correct
14 Correct 1 ms 2396 KB Output is correct
15 Correct 1 ms 2396 KB Output is correct
16 Correct 1 ms 2396 KB Output is correct
17 Correct 1 ms 2396 KB Output is correct
18 Correct 1 ms 2396 KB Output is correct
19 Correct 1 ms 2396 KB Output is correct
20 Correct 0 ms 2396 KB Output is correct
21 Correct 1 ms 2396 KB Output is correct
22 Correct 1 ms 2468 KB Output is correct
23 Correct 0 ms 2396 KB Output is correct
24 Correct 1 ms 2396 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 2392 KB Output is correct
2 Correct 0 ms 2396 KB Output is correct
3 Correct 1 ms 2396 KB Output is correct
4 Correct 1 ms 2396 KB Output is correct
5 Correct 1 ms 2396 KB Output is correct
6 Correct 1 ms 2396 KB Output is correct
7 Correct 0 ms 2396 KB Output is correct
8 Correct 0 ms 2396 KB Output is correct
9 Correct 1 ms 2396 KB Output is correct
10 Correct 0 ms 2396 KB Output is correct
11 Correct 0 ms 2396 KB Output is correct
12 Correct 0 ms 2396 KB Output is correct
13 Correct 0 ms 2520 KB Output is correct
14 Correct 1 ms 2396 KB Output is correct
15 Correct 1 ms 2396 KB Output is correct
16 Correct 1 ms 2396 KB Output is correct
17 Correct 1 ms 2396 KB Output is correct
18 Correct 1 ms 2396 KB Output is correct
19 Correct 1 ms 2396 KB Output is correct
20 Correct 0 ms 2396 KB Output is correct
21 Correct 1 ms 2396 KB Output is correct
22 Correct 1 ms 2468 KB Output is correct
23 Correct 0 ms 2396 KB Output is correct
24 Correct 1 ms 2396 KB Output is correct
25 Correct 1 ms 2396 KB Output is correct
26 Correct 14 ms 5796 KB Output is correct
27 Correct 14 ms 7004 KB Output is correct
28 Correct 14 ms 6896 KB Output is correct
29 Correct 16 ms 6996 KB Output is correct
30 Correct 12 ms 6236 KB Output is correct
31 Correct 14 ms 6976 KB Output is correct
32 Correct 14 ms 6936 KB Output is correct
33 Correct 14 ms 7256 KB Output is correct
34 Correct 13 ms 6980 KB Output is correct
35 Correct 11 ms 6304 KB Output is correct
36 Correct 11 ms 6236 KB Output is correct
37 Correct 11 ms 6408 KB Output is correct
38 Correct 14 ms 7000 KB Output is correct
39 Correct 14 ms 7084 KB Output is correct
40 Correct 15 ms 6996 KB Output is correct
41 Correct 13 ms 7004 KB Output is correct
42 Correct 12 ms 6744 KB Output is correct
43 Correct 14 ms 6996 KB Output is correct
44 Correct 15 ms 6980 KB Output is correct
45 Correct 15 ms 7044 KB Output is correct
46 Correct 17 ms 6984 KB Output is correct
47 Correct 15 ms 7000 KB Output is correct
48 Correct 15 ms 6996 KB Output is correct