結果

問題 No.1133 キムワイプイーター
ユーザー RISE70226821
提出日時 2020-08-03 17:27:01
言語 Java
(openjdk 23)
結果
AC  
実行時間 929 ms / 2,000 ms
コード長 995 bytes
コンパイル時間 2,662 ms
コンパイル使用メモリ 79,568 KB
実行使用メモリ 129,756 KB
最終ジャッジ日時 2024-09-13 10:27:31
合計ジャッジ時間 21,082 ms
ジャッジサーバーID
(参考情報)
judge1 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2
other AC * 31
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.*;
import java.lang.*;
import java.io.*;

public class Main {
	public static void main (String[] args) throws java.lang.Exception
	{
		// your code goes here
		// 入力
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int M = sc.nextInt();
		String str = sc.next();
		String[] move = str.split("");
		
		// 移動
		int[][] grid = new int[N+1][N+1];
		for(int i = 0; i <= N; i++){
			for(int j = 0; j <= N; j++){
				grid[i][j] = 1;
			}
		}
		
		int posX = 0;
		int posY = N;
		grid[N][0] = 0;
		for(int i = 0; i < M; i++){
			if(move[i].equals("R")){
				posX++;
			}
			else if(move[i].equals("L")){
				posX--;
			}
			else if(move[i].equals("D")){
				posY++;
			}
			else if(move[i].equals("U")){
				posY--;
			}
			grid[posY][posX] = 0;
		}
		
		// 出力
		for(int i = 0; i <= N; i++){
			for(int j = 0; j <= N; j++){
				System.out.print(grid[i][j] + " ");
			}
			System.out.println("");
		}
	}

}
0