File tree Expand file tree Collapse file tree 3 files changed +37
-2
lines changed Expand file tree Collapse file tree 3 files changed +37
-2
lines changed Original file line number Diff line number Diff line change
1
+ n = int (input ())
2
+ a = list (map (int , input ().split ()))
3
+
4
+ cost = [0 ]* n
5
+ cost [1 ] = abs (a [0 ]- a [1 ])
6
+
7
+ for i in range (2 , n ):
8
+ one = abs (a [i ]- a [i - 1 ])
9
+ two = abs (a [i ]- a [i - 2 ])
10
+ cost [i ] += min (cost [i - 1 ]+ one , cost [i - 2 ]+ two )
11
+
12
+ print (cost [- 1 ])
Original file line number Diff line number Diff line change
1
+ n = int (input ())
2
+ c = []
3
+ s = []
4
+ f = []
5
+ for _ in range (n - 1 ):
6
+ _c , _s , _f = map (int , input ().split ())
7
+ c .append (_c )
8
+ s .append (_s )
9
+ f .append (_f )
10
+
11
+ ans = 0
12
+
13
+ for i in range (n ):
14
+ ans = 0
15
+ for j in range (i , n - 1 ):
16
+ if ans < s [j ]:
17
+ ans = s [j ] + c [j ]
18
+ elif ans % f [j ] == 0 :
19
+ ans += c [j ]
20
+ else :
21
+ ans += f [j ] - ans % f [j ] + c [j ]
22
+
23
+ print (ans )
Original file line number Diff line number Diff line change @@ -8,7 +8,7 @@ AtCoderの問題をpython3で解いたものになります。AC確認は行っ
8
8
## [ AtCoder Beginner Contest] ( ABC )
9
9
| Problem A | Problem B | Problem C | Problem D | Problem E | Problem F |
10
10
| :---:| :---:| :---:| :---:| :---:| :---:|
11
- | 179/179 <img align =" center " src =" https://img.shields.io/badge/Completed!-green?style=for-the-badge " />| 179/179 <img align =" center " src =" https://img.shields.io/badge/Completed!-green?style=for-the-badge " />| 124 /179| 29/173| 4/54| 0/54|
11
+ | 179/179 <img align =" center " src =" https://img.shields.io/badge/Completed!-green?style=for-the-badge " />| 179/179 <img align =" center " src =" https://img.shields.io/badge/Completed!-green?style=for-the-badge " />| 126 /179| 29/173| 4/54| 0/54|
12
12
13
13
14
14
### ABC001 - ABC041
@@ -32,7 +32,7 @@ AtCoderの問題をpython3で解いたものになります。AC確認は行っ
32
32
| [ ABC016] ( ABC/ABC016 ) | [ &check ; ] ( ABC/ABC016/A.py ) | [ &check ; ] ( ABC/ABC016/B.py ) | [ &check ; ] ( ABC/ABC016/C.py ) ||| [ ABC037] ( ABC/ABC037 ) | [ &check ; ] ( ABC/ABC037/A.py ) | [ &check ; ] ( ABC/ABC037/B.py ) |||
33
33
| [ ABC017] ( ABC/ABC017 ) | [ &check ; ] ( ABC/ABC017/A.py ) | [ &check ; ] ( ABC/ABC017/B.py ) |||| [ ABC038] ( ABC/ABC038 ) | [ &check ; ] ( ABC/ABC038/A.py ) | [ &check ; ] ( ABC/ABC038/B.py ) |||
34
34
| [ ABC018] ( ABC/ABC018 ) | [ &check ; ] ( ABC/ABC018/A.py ) | [ &check ; ] ( ABC/ABC018/B.py ) |||| [ ABC039] ( ABC/ABC039 ) | [ &check ; ] ( ABC/ABC039/A.py ) | [ &check ; ] ( ABC/ABC039/B.py ) | [ &check ; ] ( ABC/ABC039/C.py ) ||
35
- | [ ABC019] ( ABC/ABC019 ) | [ &check ; ] ( ABC/ABC019/A.py ) | [ &check ; ] ( ABC/ABC019/B.py ) |||| [ ABC040] ( ABC/ABC040 ) | [ &check ; ] ( ABC/ABC040/A.py ) | [ &check ; ] ( ABC/ABC040/B.py ) |||
35
+ | [ ABC019] ( ABC/ABC019 ) | [ &check ; ] ( ABC/ABC019/A.py ) | [ &check ; ] ( ABC/ABC019/B.py ) |||| [ ABC040] ( ABC/ABC040 ) | [ &check ; ] ( ABC/ABC040/A.py ) | [ &check ; ] ( ABC/ABC040/B.py ) | [ & check ; ] ( ABC/ABC040/C.py ) ||
36
36
| [ ABC020] ( ABC/ABC020 ) | [ &check ; ] ( ABC/ABC020/A.py ) | [ &check ; ] ( ABC/ABC020/B.py ) |||| [ ABC041] ( ABC/ABC041 ) | [ &check ; ] ( ABC/ABC041/A.py ) | [ &check ; ] ( ABC/ABC041/B.py ) | [ &check ; ] ( ABC/ABC041/C.py ) ||
37
37
| [ ABC021] ( ABC/ABC021 ) | [ &check ; ] ( ABC/ABC021/A.py ) | [ &check ; ] ( ABC/ABC021/B.py ) |||||||||||
38
38
You can’t perform that action at this time.
0 commit comments