結果

問題 No.1292 パタパタ三角形
ユーザー outlineoutline
提出日時 2020-12-13 17:07:24
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 71 ms / 2,000 ms
コード長 2,774 bytes
コンパイル時間 1,397 ms
コンパイル使用メモリ 140,328 KB
実行使用メモリ 16,144 KB
最終ジャッジ日時 2023-10-20 03:53:18
合計ジャッジ時間 2,608 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,348 KB
testcase_01 AC 1 ms
4,348 KB
testcase_02 AC 2 ms
4,348 KB
testcase_03 AC 2 ms
4,348 KB
testcase_04 AC 2 ms
4,348 KB
testcase_05 AC 1 ms
4,348 KB
testcase_06 AC 2 ms
4,348 KB
testcase_07 AC 31 ms
6,196 KB
testcase_08 AC 30 ms
6,068 KB
testcase_09 AC 52 ms
15,600 KB
testcase_10 AC 54 ms
15,492 KB
testcase_11 AC 55 ms
15,392 KB
testcase_12 AC 67 ms
16,144 KB
testcase_13 AC 71 ms
16,144 KB
testcase_14 AC 12 ms
4,348 KB
testcase_15 AC 13 ms
4,348 KB
testcase_16 AC 8 ms
4,348 KB
権限があれば一括ダウンロードができます

ソースコード

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;
}
0