#import <bits/stdc++.h>
using namespace std;
using ll = long long;
using pll = pair<ll, ll>;
inline void fastio() {
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
cout.tie(nullptr);
}
ll n, ans = 1, cnt, loc;
vector<ll> arr;
int main() {
fastio();
cin >> n;
arr.resize(n);
for (ll i = 1; i < n; i++) {
cin >> arr[i];
}
for (ll i = 0, h = 0; i < n; i++) {
if (arr[i] - h > 2) {
cout << 0 << '\n';
return 0;
} else if (arr[i] - h == 2) {
if (cnt) {
cout << 0 << '\n';
return 0;
} else {
cnt = arr[i];
loc = i;
}
}
h = max(h, arr[i]);
ans += h;
}
if (cnt) {
for (ll i = 0; i < loc; i++) {
if (arr[i] + 2 == cnt) {
ans = loc - i;
break;
}
}
}
cout << ans << '\n';
return 0;
}
Compilation message
building3.cpp:1:2: warning: #import is a deprecated GCC extension [-Wdeprecated]
1 | #import <bits/stdc++.h>
| ^~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
1 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
1 ms |
344 KB |
Output is correct |
7 |
Correct |
1 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
1 ms |
604 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
1 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
1 ms |
344 KB |
Output is correct |
7 |
Correct |
1 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
1 ms |
604 KB |
Output is correct |
10 |
Correct |
0 ms |
348 KB |
Output is correct |
11 |
Correct |
0 ms |
344 KB |
Output is correct |
12 |
Correct |
0 ms |
348 KB |
Output is correct |
13 |
Correct |
1 ms |
452 KB |
Output is correct |
14 |
Correct |
1 ms |
348 KB |
Output is correct |
15 |
Correct |
0 ms |
348 KB |
Output is correct |
16 |
Correct |
1 ms |
344 KB |
Output is correct |
17 |
Correct |
0 ms |
348 KB |
Output is correct |
18 |
Correct |
0 ms |
348 KB |
Output is correct |
19 |
Correct |
0 ms |
348 KB |
Output is correct |
20 |
Correct |
1 ms |
348 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
1 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
1 ms |
344 KB |
Output is correct |
7 |
Correct |
1 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
1 ms |
604 KB |
Output is correct |
10 |
Correct |
0 ms |
348 KB |
Output is correct |
11 |
Correct |
0 ms |
344 KB |
Output is correct |
12 |
Correct |
0 ms |
348 KB |
Output is correct |
13 |
Correct |
1 ms |
452 KB |
Output is correct |
14 |
Correct |
1 ms |
348 KB |
Output is correct |
15 |
Correct |
0 ms |
348 KB |
Output is correct |
16 |
Correct |
1 ms |
344 KB |
Output is correct |
17 |
Correct |
0 ms |
348 KB |
Output is correct |
18 |
Correct |
0 ms |
348 KB |
Output is correct |
19 |
Correct |
0 ms |
348 KB |
Output is correct |
20 |
Correct |
1 ms |
348 KB |
Output is correct |
21 |
Correct |
53 ms |
12112 KB |
Output is correct |
22 |
Correct |
52 ms |
11984 KB |
Output is correct |
23 |
Correct |
52 ms |
12108 KB |
Output is correct |
24 |
Correct |
66 ms |
14924 KB |
Output is correct |
25 |
Correct |
63 ms |
14928 KB |
Output is correct |
26 |
Correct |
69 ms |
14796 KB |
Output is correct |
27 |
Correct |
63 ms |
14928 KB |
Output is correct |
28 |
Correct |
66 ms |
14804 KB |
Output is correct |
29 |
Correct |
39 ms |
10060 KB |
Output is correct |
30 |
Correct |
47 ms |
11600 KB |
Output is correct |
31 |
Correct |
57 ms |
12364 KB |
Output is correct |
32 |
Correct |
55 ms |
12368 KB |
Output is correct |
33 |
Correct |
54 ms |
12372 KB |
Output is correct |
34 |
Correct |
54 ms |
12624 KB |
Output is correct |
35 |
Correct |
79 ms |
14928 KB |
Output is correct |