結果

問題 No.1292 パタパタ三角形
ユーザー ninoinuininoinui
提出日時 2020-11-20 21:49:49
言語 C++17
(gcc 12.2.0 + boost 1.81.0)
結果
AC  
実行時間 48 ms / 2,000 ms
コード長 1,181 bytes
コンパイル時間 2,132 ms
実行使用メモリ 12,912 KB
最終ジャッジ日時 2023-02-23 18:10:48
合計ジャッジ時間 2,944 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
6,196 KB
testcase_01 AC 1 ms
6,284 KB
testcase_02 AC 1 ms
6,268 KB
testcase_03 AC 2 ms
6,184 KB
testcase_04 AC 2 ms
6,280 KB
testcase_05 AC 2 ms
6,276 KB
testcase_06 AC 2 ms
6,188 KB
testcase_07 AC 22 ms
6,204 KB
testcase_08 AC 22 ms
6,276 KB
testcase_09 AC 43 ms
12,428 KB
testcase_10 AC 40 ms
12,284 KB
testcase_11 AC 44 ms
12,328 KB
testcase_12 AC 47 ms
12,912 KB
testcase_13 AC 48 ms
12,832 KB
testcase_14 AC 3 ms
6,164 KB
testcase_15 AC 3 ms
6,256 KB
testcase_16 AC 4 ms
6,192 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;

template <typename T, typename U> bool cmin(T &a, U b) { return a > b && (a = b, true); }
template <typename T, typename U> bool cmax(T &a, U b) { return a < b && (a = b, true); }

signed main() {
  cin.tie(nullptr);
  ios_base::sync_with_stdio(false);

  string S;
  cin >> S;
  int N = S.size();
  set<pair<int, int>> SE;
  SE.insert({0, 0});
  for (int i = 0, f = 0, a = 0, b = 1, c = 2, x = 0, y = 0; i < N; i++) {
    int now = S.at(i) - 'a';
    if (f) {
      if (now == a) {
        SE.insert({x, --y});
      } else if (now == b) {
        SE.insert({--x, y});
        int tmp = a;
        a = c;
        c = b;
        b = tmp;
      } else {
        SE.insert({++x, y});
        int tmp = a;
        a = b;
        b = c;
        c = tmp;
      }
      f = 0;
    } else {
      if (now == a) {
        SE.insert({x, ++y});
      } else if (now == b) {
        SE.insert({--x, y});
        int tmp = a;
        a = c;
        c = b;
        b = tmp;
      } else {
        SE.insert({++x, y});
        int tmp = a;
        a = b;
        b = c;
        c = tmp;
      }
      f = 1;
    }
  }
  cout << SE.size() << "\n";
}
0