結果

問題 No.331 CodeRunnerでやれ
ユーザー はむ吉🐹
提出日時 2016-05-15 16:15:07
言語 Python3
(3.13.1 + numpy 2.2.1 + scipy 1.14.1)
結果
TLE  
(最新)
AC  
(最初)
実行時間 -
コード長 1,045 bytes
コンパイル時間 300 ms
コンパイル使用メモリ 12,800 KB
実行使用メモリ 113,608 KB
最終ジャッジ日時 2024-07-16 23:43:26
合計ジャッジ時間 13,302 ms
ジャッジサーバーID
(参考情報)
judge4 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample -- * 1
other TLE * 1 -- * 15
権限があれば一括ダウンロードができます

ソースコード

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()
    s.depth_first_search(0, 0, 1)


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