結果

問題 No.351 市松スライドパズル
ユーザー code-devocode-devo
提出日時 2016-03-12 02:50:25
言語 Java21
(openjdk 21)
結果
AC  
実行時間 770 ms / 2,000 ms
コード長 1,462 bytes
コンパイル時間 2,215 ms
コンパイル使用メモリ 77,876 KB
実行使用メモリ 67,884 KB
最終ジャッジ日時 2023-10-25 07:27:01
合計ジャッジ時間 11,604 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 663 ms
66,956 KB
testcase_01 AC 57 ms
53,416 KB
testcase_02 AC 56 ms
53,404 KB
testcase_03 AC 56 ms
53,412 KB
testcase_04 AC 56 ms
52,264 KB
testcase_05 AC 57 ms
53,416 KB
testcase_06 AC 56 ms
53,344 KB
testcase_07 AC 55 ms
52,264 KB
testcase_08 AC 55 ms
53,424 KB
testcase_09 AC 55 ms
52,288 KB
testcase_10 AC 55 ms
53,404 KB
testcase_11 AC 57 ms
53,408 KB
testcase_12 AC 57 ms
53,404 KB
testcase_13 AC 753 ms
67,564 KB
testcase_14 AC 751 ms
67,824 KB
testcase_15 AC 755 ms
67,240 KB
testcase_16 AC 763 ms
67,452 KB
testcase_17 AC 760 ms
67,884 KB
testcase_18 AC 757 ms
65,812 KB
testcase_19 AC 759 ms
67,572 KB
testcase_20 AC 770 ms
67,544 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.io.BufferedReader;
import java.io.Closeable;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.Arrays;
import java.util.Iterator;

public class Main {
	public static void main(String[] args) throws Exception {
		try (Scanner sc = new Scanner(System.in)) {
			int h = sc.nextInt();
			int w = sc.nextInt();
			int n = sc.nextInt();
			boolean[] rs = new boolean[n];
			int[] ks = new int[n];

			for (int i = 0; i < n; i++) {
				rs[i] = sc.next().charAt(0) == 'R';
				ks[i] = sc.nextInt();
			}

			int x = 0;
			int y = 0;
			for (int i = n - 1; i >= 0; i--) {
				if (rs[i]) {
					if (ks[i] == y) {
						x--;
						if (x < 0)
							x = w - 1;
					}
				} else {
					if (ks[i] == x) {
						y--;
						if (y < 0)
							y = h - 1;
					}
				}
			}

			System.out.println((x + y) % 2 == 0 ? "white" : "black");
		}
	}
}

class Scanner implements Closeable {
	BufferedReader br;
	Iterator<String> it;

	Scanner(InputStream in) {
		br = new BufferedReader(new InputStreamReader(in));
	}

	String next() throws RuntimeException {
		try {
			if (it == null || !it.hasNext()) {
				it = Arrays.asList(br.readLine().split(" ")).iterator();
			}
			return it.next();
		} catch (IOException e) {
			throw new IllegalStateException();
		}
	}

	int nextInt() throws RuntimeException {
		return Integer.parseInt(next());
	}

	@Override
	public void close() throws IOException {
		br.close();
	}
}
0