結果

問題 No.1951 消えたAGCT(2)
ユーザー srjywrdnprktsrjywrdnprkt
提出日時 2023-06-29 18:39:40
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 205 ms / 3,000 ms
コード長 1,397 bytes
コンパイル時間 2,033 ms
コンパイル使用メモリ 202,648 KB
実行使用メモリ 5,760 KB
最終ジャッジ日時 2023-09-20 13:43:55
合計ジャッジ時間 5,326 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 1 ms
4,376 KB
testcase_03 AC 1 ms
4,380 KB
testcase_04 AC 2 ms
4,376 KB
testcase_05 AC 2 ms
4,376 KB
testcase_06 AC 2 ms
4,380 KB
testcase_07 AC 2 ms
4,380 KB
testcase_08 AC 19 ms
5,672 KB
testcase_09 AC 20 ms
5,692 KB
testcase_10 AC 20 ms
5,760 KB
testcase_11 AC 20 ms
5,616 KB
testcase_12 AC 13 ms
4,608 KB
testcase_13 AC 5 ms
4,380 KB
testcase_14 AC 191 ms
5,444 KB
testcase_15 AC 152 ms
5,252 KB
testcase_16 AC 162 ms
5,184 KB
testcase_17 AC 204 ms
5,696 KB
testcase_18 AC 205 ms
5,752 KB
testcase_19 AC 204 ms
5,744 KB
testcase_20 AC 204 ms
5,740 KB
testcase_21 AC 20 ms
5,744 KB
testcase_22 AC 20 ms
5,628 KB
testcase_23 AC 20 ms
5,640 KB
testcase_24 AC 20 ms
5,620 KB
testcase_25 AC 19 ms
5,636 KB
testcase_26 AC 205 ms
5,632 KB
testcase_27 AC 205 ms
5,740 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>

using namespace std;
using ll = long long;

//RSQ (0-indexed)
template<class T> struct BIT {
    vector<T> bit;
    int N;

    BIT (int n){
        N = n;
        bit.resize(N);
    }

    void add(int loc, T val){
        loc++;
        while(loc <= N){
            bit[loc-1] += val;
            loc += loc & -loc;
        }
    }

    T sum(int l, int r){
        T res = _sum(r) - _sum(l-1);
        return res;
    }

    T _sum(int r){
        r++;
        T res = 0;
        while(r > 0){
            res += bit[r-1];
            r -= r & -r;
        }
        return res;
    }
};

int swp;
vector<int> cnt(26);
vector<int> v = {0, 19, 6, 2};

int atgc(){
    int res = 0;
    for (int i=0; i<4; i++) res += cnt[(26-swp+v[i]) % 26];
    return res;
}

int main(){
 
    int N, sm;
    int ch;
    string S;
    cin >> N >> S;
    BIT<int> tree(N);
    for (int i=0; i<N; i++){
        tree.add(i, 1);
        cnt[S[i]-'A']++;
    }

    while(1){
        sm = atgc();
        if (sm == 0) break;
        int l=0, r=N, c;
        while(r-l>1){
            c = (l+r)/2;
            if (tree.sum(0, c-1) < sm) l=c;
            else r=c;
        }
        tree.add(l, -1);
        ch = ((S[l]-'A')+swp) % 26;
        cnt[(26-swp+ch) % 26] -= 1;
        swp += cnt[(26-swp+ch) % 26];
        swp %= 26;
    }

    cout << N-tree.sum(0, N-1) << endl;

    return 0;
}
0