結果
問題 | No.232 めぐるはめぐる (2) |
ユーザー |
![]() |
提出日時 | 2015-10-08 11:39:25 |
言語 | Java (openjdk 23) |
結果 |
WA
|
実行時間 | - |
コード長 | 1,255 bytes |
コンパイル時間 | 2,471 ms |
コンパイル使用メモリ | 79,280 KB |
実行使用メモリ | 58,784 KB |
最終ジャッジ日時 | 2024-07-20 02:12:57 |
合計ジャッジ時間 | 11,008 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 1 WA * 2 |
other | AC * 4 WA * 18 |
ソースコード
package no232; import java.util.Scanner; public class Main { static int[] dx = {1,1,0,-1,-1,-1,0,1}; static int[] dy = {0,1,1,1,0,-1,-1,-1}; static String[] command = {">","^>","^","<^","<","<v","v","v>"}; public static void main(String[] args) { Scanner sc = new Scanner(System.in); int t = sc.nextInt(); int y = sc.nextInt(); int x = sc.nextInt(); StringBuilder ans = new StringBuilder(); while(t > 2) { StringBuilder com = new StringBuilder(); if (x > 0) { com.append('>'); x--; }else if(x < 0) { com.append('<'); x++; } if (y > 0) { com.append('^'); y--; }else if(y < 0) { com.append('v'); y++; } if (com.length() == 0) { com.append('<'); x++; } ans.append(com.toString()); ans.append('\n'); t--; } String ans2 = solve(t,x,y); if (ans2 == null) { System.out.println("NO"); }else{ System.out.println("YES"); System.out.print(ans.toString()); System.out.println(ans2); } } public static String solve(int t,int x,int y) { if (t == 0) { return x == 0 && y == 0 ? "" : null; } for(int i=0;i<8;i++) { String s = solve(t-1,x-dx[i],y-dy[i]); if (s != null) { return command[i] + "\n" + s; } } return null; } }