結果

問題 No.1292 パタパタ三角形
ユーザー startcppstartcpp
提出日時 2020-11-21 13:26:08
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,311 bytes
コンパイル時間 749 ms
コンパイル使用メモリ 75,744 KB
実行使用メモリ 16,168 KB
最終ジャッジ日時 2023-09-30 21:49:25
合計ジャッジ時間 1,976 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 2 ms
4,376 KB
testcase_03 AC 2 ms
4,504 KB
testcase_04 AC 1 ms
4,376 KB
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 AC 69 ms
16,168 KB
testcase_13 AC 62 ms
15,836 KB
testcase_14 AC 8 ms
4,376 KB
testcase_15 AC 8 ms
4,376 KB
testcase_16 AC 8 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

//色んな解法がありそう…
//
//直角三角形をパタパタする問題だと思うと、隣接箇所を4パターンに場合分けできる。
//直角三角形を「正方形マスの座標、向き(上右0、右下1、下左2、左上3)」で持ってみる。
//aを横辺、bを縦辺、cを斜辺と思うと、それぞれ向きで場合分けして(座標, 向き)を決定できる。
//あとは、setなどで(x, y, 向き)のtupleを管理すればよい。
#include <iostream>
#include <string>
#include <tuple>
#include <set>
using namespace std;

struct P {
	int x, y, dir;
	P() {}
	P(int x, int y, int dir) { this->x = x; this->y = y; this->dir = dir; }
	bool operator<(const P &r) const {
		if (x != r.x) return x < r.x;
		if (y != r.y) return y < r.y;
		return dir < r.dir;
	}
};

int main() {
	set<P> dict;
	string s; cin >> s;
	
	P pos = P(0, 0, 0);
	dict.insert(pos);
	for (int i = 0; i < s.length(); i++) {
		if (s[i] == 'a') {
			pos.dir = (pos.dir + 2) % 4;
		}
		if (s[i] == 'b') { //yoko
			if (pos.dir == 0 || pos.dir == 3) { pos.y++; }
			else { pos.y--; }
			pos.dir ^= 1;
		}
		if (s[i] == 'c') {
			if (pos.dir == 0 || pos.dir == 1) { pos.x++; }
			else { pos.x--; }
			pos.dir ^= 3;
		}
		dict.insert(pos);
	}
	
	cout << dict.size() << endl;
	return 0;
}
0