結果

問題 No.1951 消えたAGCT(2)
ユーザー KudeKude
提出日時 2022-05-21 00:24:07
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 193 ms / 3,000 ms
コード長 1,601 bytes
コンパイル時間 2,135 ms
コンパイル使用メモリ 227,644 KB
実行使用メモリ 7,196 KB
最終ジャッジ日時 2023-10-20 15:13:09
合計ジャッジ時間 5,591 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,348 KB
testcase_01 AC 1 ms
4,348 KB
testcase_02 AC 2 ms
4,348 KB
testcase_03 AC 2 ms
4,348 KB
testcase_04 AC 2 ms
4,348 KB
testcase_05 AC 2 ms
4,348 KB
testcase_06 AC 2 ms
4,348 KB
testcase_07 AC 2 ms
4,348 KB
testcase_08 AC 12 ms
7,196 KB
testcase_09 AC 9 ms
4,976 KB
testcase_10 AC 13 ms
7,196 KB
testcase_11 AC 14 ms
7,196 KB
testcase_12 AC 9 ms
6,416 KB
testcase_13 AC 4 ms
4,348 KB
testcase_14 AC 154 ms
7,072 KB
testcase_15 AC 116 ms
6,716 KB
testcase_16 AC 145 ms
6,804 KB
testcase_17 AC 164 ms
7,196 KB
testcase_18 AC 176 ms
7,196 KB
testcase_19 AC 147 ms
7,196 KB
testcase_20 AC 158 ms
7,196 KB
testcase_21 AC 10 ms
6,148 KB
testcase_22 AC 12 ms
7,196 KB
testcase_23 AC 13 ms
7,196 KB
testcase_24 AC 12 ms
7,196 KB
testcase_25 AC 8 ms
4,976 KB
testcase_26 AC 188 ms
7,196 KB
testcase_27 AC 193 ms
7,196 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
namespace {
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wunused-function"
#include<atcoder/all>
#pragma GCC diagnostic pop
using namespace std;
using namespace atcoder;
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define rrep(i,n) for(int i = (int)(n) - 1; i >= 0; i--)
#define all(x) begin(x), end(x)
#define rall(x) rbegin(x), rend(x)
template<class T> bool chmax(T& a, const T& b) { if (a < b) { a = b; return true; } else return false; }
template<class T> bool chmin(T& a, const T& b) { if (b < a) { a = b; return true; } else return false; }
using ll = long long;
using P = pair<int,int>;
using VI = vector<int>;
using VVI = vector<VI>;
using VL = vector<ll>;
using VVL = vector<VL>;

constexpr int A = 'A' - 'A';
constexpr int G = 'G' - 'A';
constexpr int C = 'C' - 'A';
constexpr int T = 'T' - 'A';

} int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n;
  cin >> n;
  VI st1(n), st2;
  int cnt[26]{};  // in original
  int rot = 0;
  rep(i, n) {
    char c;
    cin >> c;
    int x = c - 'A';
    st1[i] = x;
    cnt[x]++;
  }
  int ans = 0;
  auto is_AGCT = [](int x) {
    return x == A || x == G || x == C || x == T;
  };
  while(true) {
    int c1 = 0;
    rep(i, 26) if (is_AGCT((i + rot) % 26)) c1 += cnt[i];
    if (c1 == 0) break;
    ans++;
    while((int)st1.size() > c1) st2.emplace_back(st1.back()), st1.pop_back();
    while((int)st1.size() < c1) st1.emplace_back(st2.back()), st2.pop_back();
    int x = st1.back();
    st1.pop_back();
    int c2 = --cnt[x];
    rot += c2;
    rot %= 26;
  }
  cout << ans << '\n';
}
0