結果

問題 No.5017 Tool-assisted Shooting
ユーザー すぎぱも(sugipamo)すぎぱも(sugipamo)
提出日時 2023-07-16 17:56:05
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 169 ms / 2,000 ms
コード長 4,817 bytes
コンパイル時間 617 ms
コンパイル使用メモリ 11,224 KB
実行使用メモリ 25,260 KB
スコア 2,088,913
平均クエリ数 979.21
最終ジャッジ日時 2023-07-16 17:56:28
合計ジャッジ時間 18,605 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
純コード判定しない問題か言語
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 169 ms
24,720 KB
testcase_01 AC 132 ms
24,892 KB
testcase_02 AC 128 ms
24,616 KB
testcase_03 AC 134 ms
24,988 KB
testcase_04 AC 122 ms
25,260 KB
testcase_05 AC 123 ms
24,784 KB
testcase_06 AC 125 ms
24,900 KB
testcase_07 AC 166 ms
25,008 KB
testcase_08 AC 123 ms
24,984 KB
testcase_09 AC 123 ms
24,716 KB
testcase_10 AC 125 ms
24,736 KB
testcase_11 AC 125 ms
25,088 KB
testcase_12 AC 130 ms
24,776 KB
testcase_13 AC 129 ms
24,976 KB
testcase_14 AC 134 ms
24,928 KB
testcase_15 AC 144 ms
24,676 KB
testcase_16 AC 124 ms
25,128 KB
testcase_17 AC 127 ms
24,708 KB
testcase_18 AC 131 ms
25,008 KB
testcase_19 AC 125 ms
24,676 KB
testcase_20 AC 123 ms
24,860 KB
testcase_21 AC 134 ms
24,884 KB
testcase_22 AC 124 ms
25,088 KB
testcase_23 AC 129 ms
25,064 KB
testcase_24 AC 127 ms
24,652 KB
testcase_25 AC 128 ms
25,196 KB
testcase_26 AC 61 ms
24,524 KB
testcase_27 AC 130 ms
24,708 KB
testcase_28 AC 130 ms
24,980 KB
testcase_29 AC 121 ms
24,612 KB
testcase_30 AC 124 ms
24,884 KB
testcase_31 AC 128 ms
25,116 KB
testcase_32 AC 127 ms
24,860 KB
testcase_33 AC 130 ms
24,924 KB
testcase_34 AC 124 ms
25,076 KB
testcase_35 AC 127 ms
24,712 KB
testcase_36 AC 122 ms
25,016 KB
testcase_37 AC 126 ms
24,824 KB
testcase_38 AC 134 ms
24,600 KB
testcase_39 AC 129 ms
24,728 KB
testcase_40 AC 126 ms
24,800 KB
testcase_41 AC 122 ms
24,980 KB
testcase_42 AC 134 ms
25,116 KB
testcase_43 AC 123 ms
24,728 KB
testcase_44 AC 130 ms
24,828 KB
testcase_45 AC 131 ms
24,968 KB
testcase_46 AC 125 ms
24,948 KB
testcase_47 AC 120 ms
25,056 KB
testcase_48 AC 129 ms
24,564 KB
testcase_49 AC 123 ms
24,584 KB
testcase_50 AC 125 ms
25,132 KB
testcase_51 AC 128 ms
25,000 KB
testcase_52 AC 123 ms
24,784 KB
testcase_53 AC 153 ms
24,656 KB
testcase_54 AC 133 ms
25,200 KB
testcase_55 AC 133 ms
24,808 KB
testcase_56 AC 132 ms
25,124 KB
testcase_57 AC 129 ms
24,616 KB
testcase_58 AC 132 ms
24,648 KB
testcase_59 AC 134 ms
24,612 KB
testcase_60 AC 127 ms
24,636 KB
testcase_61 AC 132 ms
25,200 KB
testcase_62 AC 125 ms
24,932 KB
testcase_63 AC 133 ms
24,668 KB
testcase_64 AC 123 ms
25,224 KB
testcase_65 AC 133 ms
24,696 KB
testcase_66 AC 127 ms
24,912 KB
testcase_67 AC 125 ms
24,884 KB
testcase_68 AC 131 ms
24,884 KB
testcase_69 AC 125 ms
24,888 KB
testcase_70 AC 127 ms
25,152 KB
testcase_71 AC 129 ms
25,040 KB
testcase_72 AC 124 ms
25,028 KB
testcase_73 AC 129 ms
25,232 KB
testcase_74 AC 118 ms
24,820 KB
testcase_75 AC 128 ms
25,000 KB
testcase_76 AC 154 ms
24,984 KB
testcase_77 AC 134 ms
24,756 KB
testcase_78 AC 136 ms
24,700 KB
testcase_79 AC 128 ms
24,980 KB
testcase_80 AC 122 ms
24,780 KB
testcase_81 AC 123 ms
25,208 KB
testcase_82 AC 126 ms
24,928 KB
testcase_83 AC 154 ms
24,884 KB
testcase_84 AC 65 ms
24,744 KB
testcase_85 AC 128 ms
24,556 KB
testcase_86 AC 127 ms
24,916 KB
testcase_87 AC 125 ms
24,876 KB
testcase_88 AC 133 ms
24,712 KB
testcase_89 AC 131 ms
24,988 KB
testcase_90 AC 131 ms
24,604 KB
testcase_91 AC 82 ms
24,892 KB
testcase_92 AC 122 ms
24,988 KB
testcase_93 AC 122 ms
25,224 KB
testcase_94 AC 121 ms
25,064 KB
testcase_95 AC 129 ms
24,820 KB
testcase_96 AC 124 ms
25,228 KB
testcase_97 AC 131 ms
24,604 KB
testcase_98 AC 132 ms
24,800 KB
testcase_99 AC 129 ms
24,776 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

# import time
# timer = time.perf_counter()

output = []


class enemy():
    def __init__(self, hp, power, pos):
        self.hp = hp + 1
        self.power = power
        self.point = hp
        self.exp = power
        self.pos = [pos, 60]

    def move(self, p):
        self.pos[1] -= 1
        if p.pos[0] == self.pos[0] and p.pos[1] == self.pos[1]:
            return False
        return True

    def state(self):
        print("HP:{} POWER:{} POS:{}".format(self.hp, self.power, self.pos))


class enemys():
    def __init__(self):
        self.enemys = []
        self.deleted = []
        from collections import deque
        self.canattacks = [deque() for _ in range(25)]

    def states(self):
        for e in self.enemys:
            e.state()

    def expect_defeat_values(self, p):
        # ret = []
        min_ = ([], 1 << 60)
        for i in range(25):
            if not self.canattacks[i]:
                continue
            i = self.canattacks[i][0]
            e = self.enemys[i]
            t = abs(p.pos[0] - e.pos[0]) + int(e.hp / p.level)
            if e.hp % p.level != 0:
                t += 1

            t += 1

            if t >= e.pos[1]:
                continue

            if min_[1] <= t:
                continue

            if p.pos[0] < e.pos[0]:
                que = [1] * (e.pos[0] - p.pos[0])
            else:
                que = [-1] * (p.pos[0] - e.pos[0])

            if e.pos[1] < len(que):
                continue

            isok = True
            pos = [p.pos[0], p.pos[1]]
            for d in que:
                pos[1] += 1
                pos[0] += d
                if pos[0] < 0:
                    pos[0] += 25
                pos[0] = pos[0] % 25

                for c in self.canattacks[pos[0]]:
                    e_ = self.enemys[c]
                    if abs(e_.pos[1] - pos[1]) <= 2:
                        isok = False
                        break

                if not isok:
                    break

            if isok:
                min_ = (que, t)
            # ret.append((que, v))

        return min_

    def add(self, enemy):
        if self.deleted:
            i = self.deleted.pop()
        else:
            i = len(self.enemys)
            self.enemys.append([])

        self.enemys[i] = enemy
        self.canattacks[enemy.pos[0]].append(i)

    def defeat(self, i):
        for j in range(25):
            if not self.canattacks[j]:
                continue
            if i == self.canattacks[j][0]:
                self.canattacks[j].popleft()
                self.deleted.append(i)
                return

    def move(self, p):
        delque = []
        for canattack in self.canattacks:
            for i in canattack:
                e = self.enemys[i]
                b = e.move(p)
                if not b:
                    return False
                if e.pos[1] < 1:
                    delque.append(i)
        for i in delque:
            self.canattacks[self.enemys[i].pos[0]].popleft()
            self.deleted.append(i)
        return True


class player():
    def __init__(self):
        self.pos = [12, 0]
        self.level = 1
        self.exp = 0
        self.point = 0

    def states(self):
        print("POS:{} LEVEL:{} EXP:{} POINT:{}".format(
            self.pos, self.level, self.exp, self.point))

    def attack(self, enemys: enemys):
        if not enemys.canattacks[self.pos[0]]:
            return

        i = enemys.canattacks[self.pos[0]][0]
        e = enemys.enemys[i]
        e.hp -= self.level
        if e.hp <= 0:
            enemys.defeat(i)
            self.exp += e.exp
            self.level = 1 + int(self.exp / 100)
            self.point += e.point

    def move(self, dir, enemys: enemys):
        dstr = "S"
        if dir == -1:
            dstr = "L"
        if dir == 1:
            dstr = "R"
        output.append(dstr)
        print(dstr)

        self.pos[0] += dir
        if self.pos[0] < 0:
            self.pos[0] + 25
        self.pos[0] = self.pos[0] % 25

        if enemys.canattacks[self.pos[0]]:
            if enemys.enemys[enemys.canattacks[self.pos[0]][0]].pos[1] == 0:
                return False
        return True


es = enemys()
p = player()

while len(output) < 1000:
    for i in range(int(input())):
        inp = input().split()
        if int(inp[0]) == -1:
            break
        es.add(enemy(*map(int, inp)))

    que, _ = es.expect_defeat_values(p)

    p.attack(es)

    m = 0
    if que:
        m = que.pop()
    if not p.move(m, es):
        break
    if not es.move(p):
        break


# es.states()
# p.states()


# def text(output):
#     import os
#     os.remove("output.txt")
#     with open("output.txt", "w") as o:
#         for out in output:
#             print(out, file=o)


# text(output)
0