結果
| 問題 | 
                            No.1951 消えたAGCT(2)
                             | 
                    
| コンテスト | |
| ユーザー | 
                             SSRS
                         | 
                    
| 提出日時 | 2022-05-20 22:52:54 | 
| 言語 | C++14  (gcc 13.3.0 + boost 1.87.0)  | 
                    
| 結果 | 
                             
                                WA
                                 
                             
                            
                         | 
                    
| 実行時間 | - | 
| コード長 | 1,176 bytes | 
| コンパイル時間 | 1,503 ms | 
| コンパイル使用メモリ | 169,128 KB | 
| 実行使用メモリ | 6,948 KB | 
| 最終ジャッジ日時 | 2024-09-20 09:14:14 | 
| 合計ジャッジ時間 | 2,846 ms | 
| 
                            ジャッジサーバーID (参考情報)  | 
                        judge3 / judge4 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| other | AC * 9 WA * 19 | 
ソースコード
#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;
}
            
            
            
        
            
SSRS