結果
| 問題 | No.232 めぐるはめぐる (2) |
| コンテスト | |
| ユーザー |
ぴろず
|
| 提出日時 | 2015-10-08 11:42:23 |
| 言語 | Java (openjdk 25.0.1) |
| 結果 |
AC
|
| 実行時間 | 263 ms / 1,000 ms |
| コード長 | 1,253 bytes |
| 記録 | |
| コンパイル時間 | 2,463 ms |
| コンパイル使用メモリ | 82,724 KB |
| 実行使用メモリ | 47,084 KB |
| 最終ジャッジ日時 | 2024-09-14 12:40:13 |
| 合計ジャッジ時間 | 8,349 ms |
|
ジャッジサーバーID (参考情報) |
judge6 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 22 |
ソースコード
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.print(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;
}
}
ぴろず