結果
| 問題 |
No.1292 パタパタ三角形
|
| コンテスト | |
| ユーザー |
startcpp
|
| 提出日時 | 2020-11-21 13:26:08 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 1,311 bytes |
| コンパイル時間 | 646 ms |
| コンパイル使用メモリ | 74,388 KB |
| 実行使用メモリ | 16,128 KB |
| 最終ジャッジ日時 | 2024-07-23 15:36:13 |
| 合計ジャッジ時間 | 1,722 ms |
|
ジャッジサーバーID (参考情報) |
judge1 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 7 WA * 7 |
ソースコード
//色んな解法がありそう…
//
//直角三角形をパタパタする問題だと思うと、隣接箇所を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;
}
startcpp