結果

問題 No.1951 消えたAGCT(2)
ユーザー SSRSSSRS
提出日時 2022-05-20 22:52:54
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,176 bytes
コンパイル時間 2,783 ms
コンパイル使用メモリ 169,640 KB
実行使用メモリ 5,924 KB
最終ジャッジ日時 2023-10-20 13:43:20
合計ジャッジ時間 3,061 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
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 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 AC 21 ms
5,924 KB
testcase_10 AC 20 ms
5,924 KB
testcase_11 WA -
testcase_12 AC 13 ms
4,892 KB
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 WA -
testcase_23 WA -
testcase_24 WA -
testcase_25 AC 20 ms
5,924 KB
testcase_26 WA -
testcase_27 WA -
権限があれば一括ダウンロードができます

ソースコード

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 < 26; 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 + 1) <= 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