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

dict; string s; cin >> s; P pos = P(0, 0, 0); int edir[3] = {0, 1, 2}; //edir[char - 'a'] = 0:naname, 1:yoko hen, 2:tate hen dict.insert(pos); for (int i = 0; i < s.length(); i++) { int ed = edir[s[i] - 'a']; if (ed == 0) { pos.dir ^= 2; swap(edir[1], edir[2]); } if (ed == 1) { //yoko hen if (pos.dir == 0 || pos.dir == 3) { pos.y++; } else { pos.y--; } pos.dir ^= 1; } if (ed == 2) { if (pos.dir == 0 || pos.dir == 1) { pos.x++; } else { pos.x--; } pos.dir ^= 3; } dict.insert(pos); } cout << dict.size() << endl; return 0; }