結果

問題 No.331 CodeRunnerでやれ
ユーザー ぴろずぴろず
提出日時 2015-12-24 01:19:48
言語 Java21
(openjdk 21)
結果
AC  
実行時間 679 ms / 5,000 ms
コード長 2,926 bytes
コンパイル時間 2,833 ms
コンパイル使用メモリ 76,268 KB
実行使用メモリ 79,304 KB
平均クエリ数 211.76
最終ジャッジ日時 2023-09-23 22:48:19
合計ジャッジ時間 12,894 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 266 ms
70,024 KB
testcase_01 AC 279 ms
69,544 KB
testcase_02 AC 370 ms
73,900 KB
testcase_03 AC 463 ms
74,932 KB
testcase_04 AC 412 ms
74,868 KB
testcase_05 AC 482 ms
77,064 KB
testcase_06 AC 363 ms
74,840 KB
testcase_07 AC 679 ms
76,168 KB
testcase_08 AC 393 ms
72,968 KB
testcase_09 AC 620 ms
79,304 KB
testcase_10 AC 595 ms
76,996 KB
testcase_11 AC 443 ms
76,560 KB
testcase_12 AC 546 ms
77,852 KB
testcase_13 AC 635 ms
77,128 KB
testcase_14 AC 624 ms
75,852 KB
testcase_15 AC 453 ms
74,872 KB
testcase_16 AC 481 ms
77,336 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

package no331;

import java.util.ArrayDeque;
import java.util.Arrays;
import java.util.Queue;
import java.util.Scanner;

public class Main {
	public static final int N = 50;
	public static final int[] DI = {0,-1,0,1};
	public static final int[] DJ = {1,0,-1,0};
	public static final int[] DIRS = {0,1,3,2};
	
	//足立法・やばいケースがあるかも
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int[][] map = new int[N][N]; //-1:不明 0:空き 1:壁 
		for(int i=0;i<N;i++) {
			Arrays.fill(map[i], -1);
		}
		int ci = 25, cj = 25, dir = 1;
		while(true) {
			String s = sc.nextLine();
			if (s.contains("Christmas")) {
				break;
			}
			int wd = Integer.parseInt(s);
			//情報を更新
			for(int i=1;i<=wd+1;i++) {
				int wi = ci + DI[dir] * i;
				int wj = cj + DJ[dir] * i;
				if (wi < 0 || wi >= N || wj < 0 || wj >= N) {
					break;
				}
				if (i <= wd) {
					map[wi][wj] = 0;
				}else{
					map[wi][wj] = 1;
				}
			}
			//距離を計算
			int[][] dist = new int[N][N];
			for(int i=0;i<N;i++) {
				Arrays.fill(dist[i], 1<<29);
			}
			Queue<Integer> q = new ArrayDeque<Integer>();
			dist[0][0] = 0;
			q.offer(0);
			LOOP: while(!q.isEmpty()) {
				int bb = q.poll();
//				System.out.println(bb);
				int bi = bb >> 8 & 0xff;
				int bj = bb & 0xff;
				int bd = bb >> 16;
				for(int k=0;k<4;k++) {
					int ni = bi + DI[k];
					int nj = bj + DJ[k];
					if (ni < 0 || ni >= N || nj < 0 || nj >= N || map[ni][nj] == 1 || dist[ni][nj] <= bd + 1) {
						continue;
					}
					dist[ni][nj] = bd + 1;
					if (ni == ci && nj == cj) {
						break LOOP;
					}
					q.offer((bd+1) << 16 | ni << 8 | nj);
				}
			}
//			debug(ci,cj,dir,map);
			//現在の情報で近づくように移動・Bは用いない
			int turn = 0;
			LOOP: for(int k=0;k<4;k++) {
				int dir2 = (dir + DIRS[k]) % 4;
				int ni = ci + DI[dir2];
				int nj = cj + DJ[dir2];
				if (dist[ni][nj] < dist[ci][cj]) {
					if (k == 0) {
						turn = 0;
					}else if(k == 1) {
						turn = -1;
					}else{
						turn = 1;
					}
					break LOOP;
				}
			}
			if (turn == 0) {
				System.out.println("F");
				ci += DI[dir];
				cj += DJ[dir];
			}else if(turn == -1) {
				System.out.println("L");
				dir = (dir + 1) % 4;
			}else{
				System.out.println("R");
				dir = (dir + 3) % 4;
			}
		}
	}
	
	public static void debug(int ci,int cj,int dir,int[][] map) {
		StringBuilder sb = new StringBuilder();
		for(int i=0;i<N;i++) {
			for(int j=0;j<N;j++) {
				if (i == ci && j == cj) {
					if (dir == 0) {
						sb.append('>');
					}else if(dir == 1) {
						sb.append('^');
					}else if(dir == 2) {
						sb.append('<');
					}else{
						sb.append('v');
					}
					continue;
				}
				if (map[i][j] == -1) {
					sb.append('.');
				}else if(map[i][j] == 0) {
					sb.append(' ');
				}else{
					sb.append('#');
				}
			}
			sb.append('\n');
		}
		System.out.println(sb);
	}

}
0