Submission #00097


ソースコード

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define all(x) x.begin(),x.end()
#define fol(i,s,g) for(int i=(int)(s); i<(int)(g); i++)
#define fix(ans,k) fixed << setprecision(k) << (double)ans
#define total(n) n*(n+1)/2
#define lcm(a,b) (a/__gcd(a,b)*b)
int main(){
int n;
cin>>n;
vector<int> p(n), p2(n);
fol(i,0,n){
cin>>p[i];
p2[i] = p[i];
}
int ans = 0, ans2 = 0;
for (int i = 1; i < n-1; i++) {
while (p[i] > 0) {
if (p[i-1] > p[i+1]) {
p[i]--;
p[i-1]--;
ans+=2;
} else {
p[i]--;
p[i+1]--;
ans+=2;
}
}
}
if (p[0] > 0) ans += p[0];
if (p[n-1] > 0) ans += p[n-1];
for (int i = n-2; i > 0; i--) {
while(p2[i] > 0) {
if (p2[i-1] > p2[i+1]) {
p2[i]--;
p2[i-1]--;
ans2+=2;
} else {
p2[i]--;
p2[i+1]--;
ans2+=2;
}
}
}
/* fol(i,0,n) cout<<p[i]<<' ';
cout<<'\n'; */
if (p2[0] > 0) ans2 += p2[0];
if (p2[n-1] > 0) ans2 += p2[n-1];
cout<< min(ans, ans2) <<'\n';
return 0;
}

ステータス

項目 データ
問題 0006 - パンケーキの焼き上がり
ユーザー名 ei2109
投稿日時 2022-07-19 17:16:37
言語 C++17
状態 Wrong Answer
得点 0
ソースコード長 1332 Byte
最大実行時間 29 ms
最大メモリ使用量 764 KB

セット

セット 得点 Cases
1 ALL 0 / 6 *

テストケース

ファイル名 状態 実行時間 メモリ使用量 #
in01.txt AC 27 ms 476 KB
1
in02.txt AC 22 ms 448 KB
1
in03.txt AC 24 ms 420 KB
1
in04.txt AC 29 ms 396 KB
1
in05.txt AC 15 ms 496 KB
1
in06.txt AC 24 ms 600 KB
1
in07.txt AC 22 ms 572 KB
1
in08.txt AC 22 ms 544 KB
1
in09.txt AC 15 ms 516 KB
1
in10.txt AC 24 ms 616 KB
1
in11.txt AC 24 ms 452 KB
1
in12.txt AC 20 ms 552 KB
1
in13.txt AC 18 ms 524 KB
1
in14.txt AC 20 ms 496 KB
1
in15.txt AC 18 ms 472 KB
1
in16.txt AC 22 ms 436 KB
1
in17.txt AC 17 ms 536 KB
1
in18.txt AC 20 ms 512 KB
1
in19.txt WA 20 ms 480 KB
1
in20.txt AC 18 ms 456 KB
1
in21.txt AC 19 ms 556 KB
1
in22.txt AC 20 ms 648 KB
1
in23.txt AC 23 ms 712 KB
1
in24.txt AC 20 ms 648 KB
1
in25.txt AC 20 ms 704 KB
1
in26.txt AC 20 ms 764 KB
1
in27.txt AC 20 ms 560 KB
1
in28.txt AC 19 ms 620 KB
1
in29.txt AC 27 ms 680 KB
1
in30.txt AC 23 ms 736 KB
1