結果

問題 No.1951 消えたAGCT(2)
ユーザー naskyanaskya
提出日時 2022-04-29 17:45:20
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,197 bytes
コンパイル時間 2,748 ms
コンパイル使用メモリ 144,312 KB
実行使用メモリ 27,320 KB
最終ジャッジ日時 2023-09-11 08:31:31
合計ジャッジ時間 11,391 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 1 ms
4,384 KB
testcase_03 AC 2 ms
4,376 KB
testcase_04 AC 2 ms
4,380 KB
testcase_05 AC 2 ms
4,380 KB
testcase_06 AC 1 ms
4,380 KB
testcase_07 AC 1 ms
4,380 KB
testcase_08 AC 269 ms
27,160 KB
testcase_09 AC 274 ms
27,028 KB
testcase_10 AC 272 ms
27,012 KB
testcase_11 AC 272 ms
27,156 KB
testcase_12 AC 150 ms
17,544 KB
testcase_13 AC 9 ms
4,376 KB
testcase_14 WA -
testcase_15 AC 296 ms
21,236 KB
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 AC 271 ms
27,068 KB
testcase_22 AC 275 ms
27,016 KB
testcase_23 AC 271 ms
27,020 KB
testcase_24 AC 272 ms
27,132 KB
testcase_25 AC 272 ms
27,016 KB
testcase_26 WA -
testcase_27 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <algorithm>
#include <array>
#include <cassert>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <iostream>
#include <string>

constexpr auto nchars = ('Z' - 'A') + 1;

int nAGCT(const std::array<int, nchars> a, const int rot) {
  int res = 0;
  for (const auto n : {'A', 'G', 'C', 'T'})
    res += a[(((n - 'A' - rot) % nchars) + nchars) % nchars];
  return res;
}

int main() {
  int n;
  std::cin >> n;

  std::string s;
  std::cin >> s;

  assert(static_cast<int>(std::size(s)) == n);
  assert(std::all_of(s.cbegin(), s.cend(), [](const char c) { return std::isupper(c); }));

  std::array<int, nchars> cnt;
  cnt.fill(0);

  for (const char c : s)
    ++cnt[c - 'A'];

  int rot = 0, res = 0;

  __gnu_pbds::tree<int, __gnu_pbds::null_type, std::less<int>, __gnu_pbds::rb_tree_tag, __gnu_pbds::tree_order_statistics_node_update> t;
  for (int i = 0; i < n; ++i)
    t.insert(i);

  while (true) {
    int left = nAGCT(cnt, rot);

    if (left == 0) {
      std::cout << res << '\n';
      return 0;
    }

    auto iter = t.find_by_order(left - 1);
    --cnt[s[*iter] - 'A'];
    rot += cnt[s[*iter] - 'A'];
    t.erase(iter);

    ++res;
  }
}
0