結果

問題 No.331 CodeRunnerでやれ
ユーザー はむ吉🐹はむ吉🐹
提出日時 2016-05-15 16:20:15
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 342 ms / 5,000 ms
コード長 1,061 bytes
コンパイル時間 106 ms
コンパイル使用メモリ 10,976 KB
実行使用メモリ 24,928 KB
平均クエリ数 409.41
最終ジャッジ日時 2023-09-23 23:52:47
合計ジャッジ時間 6,363 ms
ジャッジサーバーID
(参考情報)
judge15 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 154 ms
24,896 KB
testcase_01 AC 169 ms
24,820 KB
testcase_02 AC 186 ms
24,404 KB
testcase_03 AC 199 ms
24,268 KB
testcase_04 AC 208 ms
24,676 KB
testcase_05 AC 194 ms
24,568 KB
testcase_06 AC 308 ms
24,812 KB
testcase_07 AC 265 ms
24,688 KB
testcase_08 AC 247 ms
24,928 KB
testcase_09 AC 312 ms
24,484 KB
testcase_10 AC 321 ms
24,896 KB
testcase_11 AC 324 ms
24,756 KB
testcase_12 AC 232 ms
24,856 KB
testcase_13 AC 287 ms
24,684 KB
testcase_14 AC 315 ms
24,328 KB
testcase_15 AC 318 ms
24,248 KB
testcase_16 AC 342 ms
24,372 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#!/usr/bin/env python3

import collections
import sys


MAX_SIZE = 20
DIST_INF = 100
DRS = [1, 0, -1, 0]
DCS = [0, 1, 0, -1]


class Solver(object):

    def __init__(self):
        self.visited = collections.defaultdict(bool)

    def depth_first_search(self, r0, c0, angle):
        self.visited[(r0, c0)] = True
        for _ in range(4):
            result = self.submit("R")
            while result >= DIST_INF:
                self.submit("F")
            angle = (angle + 1) % 4
            r = r0 + DRS[angle]
            c = c0 + DCS[angle]
            if result > 0 and not self.visited[(r, c)]:
                self.submit("F")
                self.depth_first_search(r, c, angle)
        self.submit("B")

    @staticmethod
    def submit(command):
        print(command)
        sys.stdout.flush()
        result = input()
        if result.startswith("M"):
            sys.exit()
        else:
            return int(result)


def main():
    s = Solver()
    _ = input()
    s.depth_first_search(0, 0, 1)


if __name__ == '__main__':
    main()
0