結果

問題 No.1951 消えたAGCT(2)
ユーザー 蜜蜂蜜蜂
提出日時 2022-05-19 11:29:58
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,728 bytes
コンパイル時間 3,853 ms
コンパイル使用メモリ 231,188 KB
実行使用メモリ 10,016 KB
最終ジャッジ日時 2023-10-17 19:58:04
合計ジャッジ時間 10,023 ms
ジャッジサーバーID
(参考情報)
judge14 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

//g++ 2.cpp -std=c++14 -O2 -I .
#include <bits/stdc++.h>
using namespace std;

#include <atcoder/all>
using namespace atcoder;

using ll = long long;
using ld = long double;
 
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using vld = vector<ld>;
using vvld = vector<vld>;
using vst = vector<string>;
using vvst = vector<vst>;
 
#define fi first
#define se second
#define pb push_back
#define eb emplace_back
#define pq_big(T) priority_queue<T,vector<T>,less<T>>
#define pq_small(T) priority_queue<T,vector<T>,greater<T>>
#define all(a) a.begin(),a.end()
#define rep(i,start,end) for(ll i=start;i<(ll)(end);i++)
#define per(i,start,end) for(ll i=start;i>=(ll)(end);i--)
#define uniq(a) sort(all(a));a.erase(unique(all(a)),a.end())

int op(int a,int b){
  return (int)(a+b);
}
int e(){
  return 0;
}

string agct = "AGCT";

int add=0;
vi cnt(26,0); // [i] := 元々'A'+i だったのがいくつあるか = 今は 'A'+i+add

int cntagct(){
  int res=0;
  for(char c:agct){
    int d=c-'A';
    res+=cnt[(d-add%26+26*100)%26];
  }
  return res;
}

int main(){
  ios::sync_with_stdio(false);
  cin.tie(nullptr);

  int n;
  string s;
  cin>>n>>s;

  segtree<int,op,e> seg(vi(n,1));

  for(char c:s){
    cnt[c-'A']++;
  }

  int ans=0;

  while(true){
    int c1=cntagct();
    if(!c1){
      cout<<ans<<endl;
      return 0;
    }
    ans++;

    int ng=-1,ok=n;
    while(ok-ng>1){
      int ch=(ng+ok)/2;
      if(seg.prod(0,ch+1)<c1){
        ng=ch;
      }
      else{
        ok=ch;
      }
    }

    // 元々ok番目にあったのを消す
    int c2=cnt[s[ok]-'A']-1;
    seg.set(ok,0);
    cnt[s[ok]-'A']--;

    //cout<<c1<<" "<<ok<<" "<<c2<<endl;

    add+=c2;
  }
}
0