Last active
March 27, 2026 05:34
-
-
Save omas-public/9566443620c85508d475e2275bd0d2d6 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # https://paiza.jp/poh/hatsukoi/challenge/hatsukoi_clothes6 | |
| # アイドルの下積み時代に苦労はつきもの…。節約のために、まずは光熱費を見直しましょう。 冷蔵庫の電気代は意外と見落としがちな家計の負担となっています。実際いくら使っているのか気になったあなたは試しに冷蔵庫の使用状況を観察しながら電気代を概算してみることにしました。あなたは冷蔵庫の電気代は以下のように発生すると考えました。 | |
| # | |
| # ・冷蔵庫内の温度が設定温度より高いとき冷蔵庫は 1 時間で 1 度温度を下げる「冷却」を行い、これには 1 時間あたり 2 円かかる。 | |
| # ・冷蔵庫内の温度が設定温度に等しいとき冷蔵庫は温度を等しく保つ「保温」を行い、これには 1 時間あたり 1 円かかる。 | |
| # | |
| # またものの出し入れの際に次のように冷蔵庫内の温度が変化すると考えました。 | |
| # | |
| # ・ ものを取り出すと冷蔵庫内の温度は外気に触れることでその瞬間に 3 度上がる | |
| # ・ ものを新たに入れると冷蔵庫内の温度は外気と温かいものに触れることでその瞬間に 5 度上がる | |
| # | |
| # 1 日の間(24 時間制で 0 時から次の日の 0 時になるまで)のものの出し入れの様子から予想されるこの日の電気代を求めてください。なおはじめの状態では冷蔵庫内の温度は設定温度に一致しているものとします。 | |
| # | |
| # 例) | |
| # | |
| # 5時にものを取り出す | |
| # 12時にものを入れる | |
| # 14時にものを取り出す | |
| # 21時にものを入れる | |
| # | |
| # この日の冷蔵庫内の温度と設定温度の差の推移は以下のようになります。 | |
| # | |
| # | |
| # | |
| # 電気代の概算 → 2 × 14 + 1 × 10 = 38 円 | |
| from bisect import bisect | |
| from sys import stdin | |
| # utility function | |
| identity = I = lambda x: x | |
| consistent = K = lambda x: lambda y: x | |
| bisect_pick = lambda d, value: list(d.values())[bisect(list(d.keys()), value) - 1] | |
| join = lambda sep="\n", fn=str: lambda values: sep.join(map(fn, values)) | |
| split = lambda sep=" ", fn=I: lambda v: list(map(fn, v.split(sep))) | |
| # 入力を受け取り,リストにして返す関数 | |
| def gets(n, fn=I): | |
| return [fn(line) for line in stdin.read().splitlines()][:n] | |
| # 出力関数 | |
| def puts(value, fn=str): | |
| print(fn(value)) | |
| # 入力データを受取り加工して返す関数 | |
| def main(p): | |
| from functools import reduce | |
| mfun = lambda d: lambda key: {'in':5, 'out':3}.get(d.get(str(key)), 0) | |
| rfun = lambda acc, v: [*acc, v] if acc[-1] == 0 else [*acc, acc[-1] - 1 + v] | |
| buff = reduce(rfun, map(mfun(dict(p)), range(1, 24)), [0]) | |
| return buff | |
| # 出力用に加工する関数 | |
| def transform(p): | |
| buff = (len(p) - p.count(0)) * 2 + p.count(0) | |
| return buff | |
| if __name__ == "__main__": | |
| # preprocessing | |
| _in = gets(int(input()), split()) | |
| # main function | |
| _out = main(_in) | |
| # display | |
| puts(transform(_out)) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment