結果

問題 No.1951 消えたAGCT(2)
ユーザー naskyanaskya
提出日時 2022-04-29 18:26:05
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 418 ms / 3,000 ms
コード長 1,204 bytes
コンパイル時間 2,251 ms
コンパイル使用メモリ 144,472 KB
実行使用メモリ 27,256 KB
最終ジャッジ日時 2023-09-11 09:05:14
合計ジャッジ時間 9,833 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 AC 2 ms
4,376 KB
testcase_03 AC 1 ms
4,380 KB
testcase_04 AC 2 ms
4,376 KB
testcase_05 AC 2 ms
4,380 KB
testcase_06 AC 2 ms
4,380 KB
testcase_07 AC 2 ms
4,376 KB
testcase_08 AC 277 ms
27,016 KB
testcase_09 AC 275 ms
27,032 KB
testcase_10 AC 275 ms
26,968 KB
testcase_11 AC 281 ms
27,084 KB
testcase_12 AC 153 ms
17,540 KB
testcase_13 AC 9 ms
4,380 KB
testcase_14 AC 383 ms
25,448 KB
testcase_15 AC 298 ms
21,228 KB
testcase_16 AC 318 ms
22,292 KB
testcase_17 AC 411 ms
26,972 KB
testcase_18 AC 418 ms
27,084 KB
testcase_19 AC 411 ms
27,020 KB
testcase_20 AC 412 ms
27,160 KB
testcase_21 AC 283 ms
26,952 KB
testcase_22 AC 277 ms
27,012 KB
testcase_23 AC 278 ms
27,084 KB
testcase_24 AC 277 ms
27,024 KB
testcase_25 AC 278 ms
26,960 KB
testcase_26 AC 411 ms
27,160 KB
testcase_27 AC 414 ms
27,256 KB
権限があれば一括ダウンロードができます

ソースコード

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 + 2 * 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 = (rot + cnt[s[*iter] - 'A']) % nchars;
    t.erase(iter);

    ++res;
  }
}
0