結果

問題 No.1292 パタパタ三角形
ユーザー ks2mks2m
提出日時 2020-11-20 23:30:47
言語 Java21
(openjdk 21)
結果
AC  
実行時間 575 ms / 2,000 ms
コード長 1,796 bytes
コンパイル時間 2,616 ms
コンパイル使用メモリ 76,892 KB
実行使用メモリ 84,016 KB
最終ジャッジ日時 2023-09-30 20:08:47
合計ジャッジ時間 8,090 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 76 ms
50,612 KB
testcase_01 AC 81 ms
52,180 KB
testcase_02 AC 76 ms
51,924 KB
testcase_03 AC 77 ms
52,308 KB
testcase_04 AC 88 ms
50,316 KB
testcase_05 AC 77 ms
52,380 KB
testcase_06 AC 74 ms
50,700 KB
testcase_07 AC 362 ms
63,848 KB
testcase_08 AC 357 ms
64,256 KB
testcase_09 AC 463 ms
78,828 KB
testcase_10 AC 496 ms
82,836 KB
testcase_11 AC 425 ms
78,708 KB
testcase_12 AC 424 ms
78,472 KB
testcase_13 AC 575 ms
84,016 KB
testcase_14 AC 283 ms
57,884 KB
testcase_15 AC 326 ms
59,756 KB
testcase_16 AC 295 ms
59,168 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.Arrays;
import java.util.HashSet;
import java.util.Set;

public class Main {
	public static void main(String[] args) throws Exception {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		char[] s = br.readLine().toCharArray();
		br.close();

		int[] dx = {1, 0, 0};
		int[] dy = {0, 1, -1};
		int x = 0;
		int y = 0;
		Set<String> set = new HashSet<>();
		set.add(toStr(x, y));
		for (int i = 0; i < s.length; i++) {
			int tx = dx[s[i] - 'a'];
			int ty = dy[s[i] - 'a'];
			if ((tx == 1 && ty == 0) || (tx == -1 && ty == 0)) {
				for (int j = 0; j < 3; j++) {
					if (dx[j] == tx && dy[j] == ty) {
						dx[j] = -dx[j];
					}
				}
			} else if (tx == 0 && ty == 1) {
				int[] nx = Arrays.copyOf(dx, 3);
				int[] ny = Arrays.copyOf(dy, 3);
				int bx = 0;
				for (int j = 0; j < 3; j++) {
					if (dx[j] == tx && dy[j] == ty) {
						ny[j] = -1;
					} else if (dy[j] == 0) {
						bx = dx[j];
						nx[j] = 0;
						ny[j] = 1;
					}
				}
				for (int j = 0; j < 3; j++) {
					if (dy[j] == -1) {
						nx[j] = -bx;
						ny[j] = 0;
					}
				}
				dx = nx;
				dy = ny;
			} else if (tx == 0 && ty == -1) {
				int[] nx = Arrays.copyOf(dx, 3);
				int[] ny = Arrays.copyOf(dy, 3);
				int bx = 0;
				for (int j = 0; j < 3; j++) {
					if (dx[j] == tx && dy[j] == ty) {
						ny[j] = 1;
					} else if (dy[j] == 0) {
						bx = dx[j];
						nx[j] = 0;
						ny[j] = -1;
					}
				}
				for (int j = 0; j < 3; j++) {
					if (dy[j] == 1) {
						nx[j] = -bx;
						ny[j] = 0;
					}
				}
				dx = nx;
				dy = ny;
			}
			x += tx;
			y += ty;
			set.add(toStr(x, y));
		}
		System.out.println(set.size());
	}

	static String toStr(int x, int y) {
		return x + "," + y;
	}
}
0