結果
| 問題 |
No.1292 パタパタ三角形
|
| コンテスト | |
| ユーザー |
startcpp
|
| 提出日時 | 2020-11-21 13:38:59 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 1,541 bytes |
| コンパイル時間 | 646 ms |
| コンパイル使用メモリ | 77,024 KB |
| 実行使用メモリ | 16,128 KB |
| 最終ジャッジ日時 | 2024-07-23 15:36:30 |
| 合計ジャッジ時間 | 1,648 ms |
|
ジャッジサーバーID (参考情報) |
judge5 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 7 WA * 7 |
ソースコード
//色んな解法がありそう…
//
//直角三角形をパタパタする問題だと思うと、隣接箇所を4パターンに場合分けできる。
//直角三角形を「正方形マスの座標、向き(上右0、右下1、下左2、左上3)」で持ってみる。
//aを横辺、bを縦辺、cを斜辺と思うと、それぞれ向きで場合分けして(座標, 向き)を決定できる。
//・そう思えないところが嘘。bが縦辺と対応したままとは限らない。
//あとは、setなどで(x, y, 向き)のtupleを管理すればよい。
#include <iostream>
#include <string>
#include <tuple>
#include <set>
#include <algorithm>
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);
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;
}
startcpp