結果

問題 No.232 めぐるはめぐる (2)
ユーザー kichirb3kichirb3
提出日時 2018-04-02 15:30:52
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 144 ms / 1,000 ms
コード長 2,219 bytes
コンパイル時間 748 ms
コンパイル使用メモリ 11,000 KB
実行使用メモリ 17,776 KB
最終ジャッジ日時 2023-10-12 13:48:36
合計ジャッジ時間 2,545 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 114 ms
11,508 KB
testcase_01 AC 144 ms
17,776 KB
testcase_02 AC 113 ms
11,508 KB
testcase_03 AC 118 ms
11,528 KB
testcase_04 AC 16 ms
8,128 KB
testcase_05 AC 16 ms
8,044 KB
testcase_06 AC 16 ms
8,056 KB
testcase_07 AC 16 ms
8,176 KB
testcase_08 AC 101 ms
13,908 KB
testcase_09 AC 16 ms
8,096 KB
testcase_10 AC 16 ms
8,092 KB
testcase_11 AC 16 ms
8,096 KB
testcase_12 AC 16 ms
8,012 KB
testcase_13 AC 16 ms
8,128 KB
testcase_14 AC 16 ms
8,072 KB
testcase_15 AC 16 ms
8,056 KB
testcase_16 AC 17 ms
8,072 KB
testcase_17 AC 16 ms
8,072 KB
testcase_18 AC 17 ms
8,352 KB
testcase_19 AC 16 ms
8,120 KB
testcase_20 AC 16 ms
8,068 KB
testcase_21 AC 16 ms
8,044 KB
testcase_22 AC 17 ms
8,092 KB
testcase_23 AC 16 ms
8,028 KB
testcase_24 AC 16 ms
8,020 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

# -*- coding: utf-8 -*-
"""
No.232 めぐるはめぐる (2)
https://yukicoder.me/problems/no/232

"""
import sys
from sys import stdin
input = stdin.readline

cx = 0
cy = 0

def last_step(steps, gx, gy):
    nx, ny = '', ''
    if cx < gx:
        nx = '>'
    elif cx > gx:
        nx = '<'
    if cy < gy:
        ny = '^'
    elif cy > gy:
        ny = 'v'
    steps.append('{}{}'.format(nx, ny))


def guruguru(steps, gx, gy):
    global cx, cy
    dx = gx - cx
    dy = gy - cy
    if dx == 1 and dy == 1:
        steps.append('^')
        cy += 1
    elif dx == 1 and dy == 0:
        steps.append('^')
        cy += 1
    elif dx == 1 and dy == -1:
        steps.append('>')
        cx += 1
    elif dx == 0 and dy == -1:
        steps.append('>')
        cx += 1
    elif dx == -1 and dy == -1:
        steps.append('v')
        cy -= 1
    elif dx == -1 and dy == 0:
        steps.append('v')
        cy -= 1
    elif dx == -1 and dy == 1:
        steps.append('<')
        cx -= 1
    else:
        steps.append('<')
        cx -= 1

def one_step_closer(steps, gx, gy):
    global cx, cy
    nx, ny = '', ''
    dx = gx - cx
    dy = gy - cy
    if max(abs(dx), abs(dy)) <= 1:
        guruguru(steps, gx, gy)
    else:
        if dx > 0:
            nx = '>'
            cx += 1
        elif dx < 0:
            nx = '<'
            cx -= 1
        if dy > 0:
            ny = '^'
            cy += 1
        elif dy < 0:
            ny = 'v'
            cy -= 1
        steps.append('{}{}'.format(nx, ny))


def solve(T, A, B):
    ans = []
    global cx, cy
    cx, cy = 0, 0
    gx, gy = B, A
    if gx > T or gy > T:
        return ans
    if cx == gx and cy == gy:
        if T == 1:
            return ans
        else:
            ans.append('{}{}'.format('>', ''))
            cx += 1
            T -= 1
    while T:
        if T == 1:
            last_step(ans, gx, gy)
            return ans
        else:
            one_step_closer(ans, gx, gy)
            T -= 1


def main(args):
    T, A, B = map(int, input().split())
    ans = solve(T, A, B)
    if not ans:
        print('NO')
    else:
        print('YES')
        print(*ans, sep='\n')


if __name__ == '__main__':
    main(sys.argv[1:])
0