結果

問題 No.1943 消えたAGCT(1)
ユーザー naskyanaskya
提出日時 2022-04-13 21:40:04
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 73 ms / 2,000 ms
コード長 768 bytes
コンパイル時間 585 ms
コンパイル使用メモリ 76,156 KB
実行使用メモリ 19,112 KB
最終ジャッジ日時 2023-09-09 03:31:28
合計ジャッジ時間 3,757 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 AC 2 ms
4,376 KB
testcase_03 AC 2 ms
4,380 KB
testcase_04 AC 1 ms
4,376 KB
testcase_05 AC 1 ms
4,376 KB
testcase_06 AC 1 ms
4,376 KB
testcase_07 AC 1 ms
4,376 KB
testcase_08 AC 1 ms
4,380 KB
testcase_09 AC 67 ms
18,976 KB
testcase_10 AC 58 ms
19,056 KB
testcase_11 AC 57 ms
19,112 KB
testcase_12 AC 62 ms
19,096 KB
testcase_13 AC 36 ms
12,744 KB
testcase_14 AC 3 ms
4,376 KB
testcase_15 AC 64 ms
18,112 KB
testcase_16 AC 52 ms
15,304 KB
testcase_17 AC 53 ms
16,060 KB
testcase_18 AC 68 ms
18,984 KB
testcase_19 AC 67 ms
18,984 KB
testcase_20 AC 65 ms
19,032 KB
testcase_21 AC 64 ms
19,032 KB
testcase_22 AC 72 ms
19,032 KB
testcase_23 AC 73 ms
19,028 KB
testcase_24 AC 59 ms
18,992 KB
testcase_25 AC 59 ms
19,100 KB
testcase_26 AC 59 ms
18,980 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <algorithm>
#include <iostream>
#include <iterator>
#include <list>

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

  std::list<char> s;
  std::copy_n(std::istream_iterator<char>(std::cin), n, std::back_inserter(s));

  const auto is_AGCT = [](const char c) {
    return c == 'A' || c == 'G' || c == 'C' || c == 'T';
  };

  auto to_remove = std::count_if(s.cbegin(), s.cend(), is_AGCT);
  if (to_remove == 0) {
    std::cout << "0\n";
    return 0;
  }

  auto iter = std::next(s.begin(), to_remove - 1);
  int res   = 0;

  while (true) {
    bool f = is_AGCT(*iter);
    iter   = s.erase(iter);
    ++res;
    if (f) {
      if (to_remove == 1) {
        break;
      } else {
        --to_remove;
        --iter;
      }
    }
  }

  std::cout << res << '\n';
}
0