結果

問題 No.1951 消えたAGCT(2)
ユーザー SSRSSSRS
提出日時 2022-05-20 23:00:05
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 199 ms / 3,000 ms
コード長 1,170 bytes
コンパイル時間 4,218 ms
コンパイル使用メモリ 168,752 KB
実行使用メモリ 5,888 KB
最終ジャッジ日時 2023-10-20 13:52:29
合計ジャッジ時間 4,608 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,348 KB
testcase_01 AC 2 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 21 ms
5,888 KB
testcase_09 AC 22 ms
5,888 KB
testcase_10 AC 22 ms
5,888 KB
testcase_11 AC 22 ms
5,888 KB
testcase_12 AC 14 ms
4,856 KB
testcase_13 AC 5 ms
4,348 KB
testcase_14 AC 186 ms
5,648 KB
testcase_15 AC 149 ms
5,384 KB
testcase_16 AC 157 ms
5,384 KB
testcase_17 AC 198 ms
5,888 KB
testcase_18 AC 197 ms
5,888 KB
testcase_19 AC 198 ms
5,888 KB
testcase_20 AC 198 ms
5,888 KB
testcase_21 AC 21 ms
5,888 KB
testcase_22 AC 21 ms
5,888 KB
testcase_23 AC 21 ms
5,888 KB
testcase_24 AC 21 ms
5,888 KB
testcase_25 AC 21 ms
5,888 KB
testcase_26 AC 199 ms
5,888 KB
testcase_27 AC 198 ms
5,888 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
template <typename T>
struct binary_indexed_tree{
  int N;
  vector<T> BIT;
  binary_indexed_tree(int N): N(N), BIT(N + 1, 0){
  }
  void add(int i, T x){
    i++;
    while (i <= N){
      BIT[i] += x;
      i += i & -i;
    }
  }
  T sum(int i){
    T ans = 0;
    while (i > 0){
      ans += BIT[i];
      i -= i & -i;
    }
    return ans;
  }
  T sum(int L, int R){
    return sum(R) - sum(L);
  }
};
int main(){
  int n;
  cin >> n;
  string s;
  cin >> s;
  vector<int> cnt(26, 0);
  for (int i = 0; i < n; i++){
    cnt[s[i] - 'A']++;
  }
  binary_indexed_tree<int> BIT(n);
  for (int i = 0; i < n; i++){
    BIT.add(i, 1);
  }
  int ans = 0;
  int sh = 0;
  while (true){
    int c1 = cnt[(26 - sh) % 26] + cnt[(28 - sh) % 26] + cnt[(32 - sh) % 26] + cnt[(45 - sh) % 26];
    if (c1 == 0){
      break;
    }
    int tv = 0, fv = n;
    while (fv - tv > 1){
      int mid = (tv + fv) / 2;
      if (BIT.sum(mid) < c1){
        tv = mid;
      } else {
        fv = mid;
      }
    }
    BIT.add(tv, -1);
    int t = s[tv] - 'A';
    cnt[t]--;
    sh += cnt[t];
    sh %= 26;
    ans++;
  }
  cout << ans << endl;
}
0