結果
問題 | No.1292 パタパタ三角形 |
ユーザー |
![]() |
提出日時 | 2020-11-20 23:30:47 |
言語 | Java (openjdk 23) |
結果 |
AC
|
実行時間 | 486 ms / 2,000 ms |
コード長 | 1,796 bytes |
コンパイル時間 | 2,701 ms |
コンパイル使用メモリ | 81,044 KB |
実行使用メモリ | 82,564 KB |
最終ジャッジ日時 | 2024-07-23 13:57:45 |
合計ジャッジ時間 | 7,392 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 14 |
ソースコード
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;}}