結果
問題 | No.1292 パタパタ三角形 |
ユーザー |
|
提出日時 | 2020-12-13 17:07:24 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 81 ms / 2,000 ms |
コード長 | 2,774 bytes |
コンパイル時間 | 1,804 ms |
コンパイル使用メモリ | 134,680 KB |
最終ジャッジ日時 | 2025-01-16 23:39:33 |
ジャッジサーバーID (参考情報) |
judge3 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 14 |
ソースコード
#include <iostream>#include <vector>#include <algorithm>#include <cmath>#include <queue>#include <string>#include <map>#include <set>#include <stack>#include <tuple>#include <deque>#include <array>#include <numeric>#include <bitset>#include <iomanip>#include <cassert>#include <chrono>#include <random>#include <limits>#include <iterator>#include <functional>#include <sstream>#include <fstream>#include <complex>#include <cstring>#include <unordered_map>using namespace std;using ll = long long;using P = pair<int, int>;constexpr int INF = 1001001001;constexpr int mod = 1000000007;// constexpr int mod = 998244353;template<class T>inline bool chmax(T& x, T y){if(x < y){x = y;return true;}return false;}template<class T>inline bool chmin(T& x, T y){if(x > y){x = y;return true;}return false;}// a/\b// /__\// c// 初期重心 (0, 0) から// a を選択 -> (-1, √3)// b を選択 -> (1, √3)// c を選択 -> (0, -2√3)// と移動するように縮尺を調整して、訪問した重心座標の整数係数を set で管理しておくint main(){ios::sync_with_stdio(false);cin.tie(nullptr);string s;cin >> s;int n = s.length();// 重心set<pair<ll, ll>> center;center.emplace(0, 0);// 整数係数ll x = 0, y = 0;// dir : 三角形の向き (0, 1) -> (上, 下)int dir = 0;// move_dir[i] : 文字 ch がどの方向に行くか// 初期の移動方向 (a(0), b(1), c(2)) -> (左(0), 右(1), 上下(2))vector<int> move_dir(3);for(int i = 0; i < 3; ++i) move_dir[i] = i;for(int i = 0; i < n; ++i){int j = s[i] - 'a';if(move_dir[j] == 2){if(dir == 0) y -= 2;else y += 2;}else{if(move_dir[j] == 1) x += 1;else x -= 1;if(dir == 0) y += 1;else y -= 1;// move_dir の更新// まず、(文字 -> 向き) を (向き -> 文字)に変換vector<int> nxt(3);for(int k = 0; k < 3; ++k){nxt[move_dir[k]] = k;}// 向きの変更if(move_dir[j] == 1){swap(nxt[0], nxt[1]);swap(nxt[1], nxt[2]);}else{swap(nxt[2], nxt[0]);swap(nxt[1], nxt[2]);}// (文字 -> 向き) の対応関係に戻すfor(int k = 0; k < 3; ++k){move_dir[nxt[k]] = k;}}dir ^= 1;center.emplace(x, y);}cout << center.size() << '\n';return 0;}