結果
| 問題 |
No.232 めぐるはめぐる (2)
|
| コンテスト | |
| ユーザー |
kichirb3
|
| 提出日時 | 2018-04-02 15:30:52 |
| 言語 | Python3 (3.13.1 + numpy 2.2.1 + scipy 1.14.1) |
| 結果 |
AC
|
| 実行時間 | 183 ms / 1,000 ms |
| コード長 | 2,219 bytes |
| コンパイル時間 | 337 ms |
| コンパイル使用メモリ | 12,800 KB |
| 実行使用メモリ | 18,944 KB |
| 最終ジャッジ日時 | 2024-09-14 12:44:45 |
| 合計ジャッジ時間 | 2,929 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 22 |
ソースコード
# -*- 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:])
kichirb3