結果

問題 No.1292 パタパタ三角形
ユーザー outline
提出日時 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
権限があれば一括ダウンロードができます

ソースコード

diff #
プレゼンテーションモードにする

#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;
}
הההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההה
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
0