結果

問題 No.331 CodeRunnerでやれ
ユーザー はむ吉🐹
提出日時 2016-05-15 16:20:15
言語 Python3
(3.13.1 + numpy 2.2.1 + scipy 1.14.1)
結果
AC  
実行時間 400 ms / 5,000 ms
コード長 1,061 bytes
コンパイル時間 339 ms
コンパイル使用メモリ 12,672 KB
実行使用メモリ 27,736 KB
平均クエリ数 409.41
最終ジャッジ日時 2024-07-16 23:42:48
合計ジャッジ時間 8,064 ms
ジャッジサーバーID
(参考情報)
judge5 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 1
other AC * 16
権限があれば一括ダウンロードができます

ソースコード

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