結果

問題 No.498 ワープクリスタル (給料日編)
ユーザー shout_poorshout_poor
提出日時 2017-04-05 13:01:35
言語 Python2
(2.7.18)
結果
TLE  
実行時間 -
コード長 1,332 bytes
コンパイル時間 198 ms
コンパイル使用メモリ 6,604 KB
実行使用メモリ 10,588 KB
最終ジャッジ日時 2023-09-22 19:45:20
合計ジャッジ時間 4,018 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 12 ms
10,588 KB
testcase_01 AC 11 ms
5,940 KB
testcase_02 AC 11 ms
6,156 KB
testcase_03 AC 12 ms
6,056 KB
testcase_04 TLE -
testcase_05 -- -
testcase_06 -- -
testcase_07 -- -
testcase_08 -- -
testcase_09 -- -
testcase_10 -- -
testcase_11 -- -
testcase_12 -- -
testcase_13 -- -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
testcase_22 -- -
testcase_23 -- -
testcase_24 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

import resource
from copy import copy

# Question: https://yukicoder.me/problems/no/498

DIV_CONST = 1000000007


def trace(goal_x, goal_y, crystals):

    memo = {}

    def local_iter(node):
        if node not in memo:
            (x, y, remain_crystals) = node
            count = 1 if (x, y) == (goal_x, goal_y) else 0
            for crystal in remain_crystals:
                next_x = x + crystal[0]
                next_y = y + crystal[1]
                next_remains = remain_crystals - {crystal}
                if crystal[2] > 1:
                    next_remains = next_remains \
                                   | {(crystal[0], crystal[1], crystal[2] - 1)}
                count = count + local_iter((next_x, next_y, next_remains))

            memo[node] = count

        return memo[node]

    return local_iter((0, 0, crystals))


def load_input(crystal_kinds):
    for l in range(crystal_kinds):
        [x, y, num] = [int(s) for s in raw_input().split()]
        yield (x, y, num)


if __name__ == '__main__':
    # from time import time
    [goal_x, goal_y, crystal_kinds] = [int(s) for s in raw_input().split()]
    # start_time = time()
    crystals = frozenset(load_input(crystal_kinds))
    # proc_time = time() - start_time
    print trace(goal_x, goal_y, crystals)
    # print "time: %f[sec]" % proc_time
0