結果

問題 No.1292 パタパタ三角形
ユーザー momoharamomohara
提出日時 2020-11-27 12:43:05
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 67 ms / 2,000 ms
コード長 2,960 bytes
コンパイル時間 2,550 ms
コンパイル使用メモリ 208,348 KB
実行使用メモリ 16,000 KB
最終ジャッジ日時 2023-10-01 04:10:19
合計ジャッジ時間 3,591 ms
ジャッジサーバーID
(参考情報)
judge14 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 AC 1 ms
4,380 KB
testcase_03 AC 2 ms
4,376 KB
testcase_04 AC 2 ms
4,380 KB
testcase_05 AC 1 ms
4,376 KB
testcase_06 AC 2 ms
4,380 KB
testcase_07 AC 27 ms
5,928 KB
testcase_08 AC 27 ms
5,760 KB
testcase_09 AC 57 ms
15,348 KB
testcase_10 AC 55 ms
15,380 KB
testcase_11 AC 60 ms
15,276 KB
testcase_12 AC 67 ms
15,928 KB
testcase_13 AC 65 ms
16,000 KB
testcase_14 AC 4 ms
4,380 KB
testcase_15 AC 5 ms
4,376 KB
testcase_16 AC 5 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
/*
#include <atcoder/all>
using namespace atcoder;
*/
#define all(hoge) (hoge).begin(), (hoge).end()
#define en '\n'
using ll = long long;
using ull = unsigned long long;
#define rep(i, m, n) for(ll i = (ll)(m); i < (ll)(n); ++i)
#define rep2(i, m, n) for(ll i = (ll)(n)-1; i >= (ll)(m); --i)
#define REP(i, n) rep(i, 0, n)
#define REP2(i, n) rep2(i, 0, n)
template <class T>
using vec = vector<T>;
template <class T>
using vvec = vector<vec<T>>;
typedef pair<ll, ll> P;
using tp = tuple<ll, ll, ll>;

constexpr long long INF = 1LL << 60;
constexpr int INF_INT = 1 << 25;
constexpr long long MOD = (ll)1e9 + 7;
//constexpr long long MOD = 998244353LL;
using ld = long double;
static const ld pi = 3.141592653589793L;

using Array = vector<ll>;
using Matrix = vector<Array>;

/*
#pragma GCC target("avx2")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
*/

template <class T>
inline bool chmin(T &a, T b) {
    if(a > b) {
        a = b;
        return true;
    }
    return false;
}
template <class T>
inline bool chmax(T &a, T b) {
    if(a < b) {
        a = b;
        return true;
    }
    return false;
}

//グラフ関連
struct Edge {
    ll to, cap, rev;
    Edge(ll _to, ll _cap, ll _rev) {
        to = _to;
        cap = _cap;
        rev = _rev;
    }
};
typedef vector<Edge> Edges;
typedef vector<Edges> Graph;

void add_edge(Graph &G, ll from, ll to, ll cap, bool revFlag, ll revCap) {
    G[from].push_back(Edge(to, cap, (ll)G[to].size()));
    if(revFlag)
        G[to].push_back(Edge(from, revCap, (ll)G[from].size() - 1));
}

void solve() {
    string s;
    cin >> s;
    int n = s.size();
    set<P> st; //行ける場所の集合
    int x = 0;
    int y = 0;
    st.insert({x, y});
    REP(i, n) {
        int d = s[i] - 'a';
        if((x + y) % 2) {
            //下向き
            int nx = x + ((abs(x) % 2) ? 3 : 0);
            nx /= 2;
            if(nx < 0) {
                nx = 3 - abs(nx) % 3;
            }
            nx %= 3;
            ll t = (3 + d - nx) % 3;
            if(t == 0) {
                y++;
            } else if(t == 1) {
                x++;
            } else {
                x--;
            }
            st.insert({x, y});
        } else {
            //上むき
            int nx = x + ((abs(x) % 2) ? 3 : 0);
            nx /= 2;
            if(nx < 0) {
                nx = 3 - abs(nx) % 3;
            }
            nx %= 3;
            ll t = (3 + d - nx) % 3;
            if(t == 0) {
                y--;
            } else if(t == 1) {
                x++;
            } else {
                x--;
            }
            st.insert({x, y});
        }
        //cout << x << " " << y << en;
    }
    cout << st.size() << en;
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    /*
    ll t;
    cin >> t;
    REP(i, t - 1) {
        solve();
    }*/

    solve();

    return 0;
}
0