結果
問題 | No.1951 消えたAGCT(2) |
ユーザー | 蜜蜂 |
提出日時 | 2022-05-19 11:53:59 |
言語 | C++14 (gcc 12.3.0 + boost 1.83.0) |
結果 |
AC
|
実行時間 | 720 ms / 3,000 ms |
コード長 | 1,797 bytes |
コンパイル時間 | 4,463 ms |
コンパイル使用メモリ | 231,080 KB |
実行使用メモリ | 10,064 KB |
最終ジャッジ日時 | 2023-10-17 20:24:51 |
合計ジャッジ時間 | 11,157 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 | 8 ms
10,064 KB |
testcase_09 | AC | 8 ms
10,064 KB |
testcase_10 | AC | 8 ms
10,064 KB |
testcase_11 | AC | 9 ms
10,064 KB |
testcase_12 | AC | 8 ms
9,008 KB |
testcase_13 | AC | 13 ms
4,348 KB |
testcase_14 | AC | 646 ms
9,800 KB |
testcase_15 | AC | 512 ms
9,272 KB |
testcase_16 | AC | 550 ms
9,536 KB |
testcase_17 | AC | 693 ms
10,064 KB |
testcase_18 | AC | 720 ms
10,064 KB |
testcase_19 | AC | 685 ms
10,064 KB |
testcase_20 | AC | 688 ms
10,064 KB |
testcase_21 | AC | 8 ms
10,064 KB |
testcase_22 | AC | 8 ms
10,064 KB |
testcase_23 | AC | 8 ms
10,064 KB |
testcase_24 | AC | 7 ms
10,064 KB |
testcase_25 | AC | 8 ms
10,064 KB |
testcase_26 | AC | 707 ms
10,064 KB |
testcase_27 | AC | 702 ms
10,064 KB |
ソースコード
//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; } } assert(seg.get(ok)==1); assert(seg.prod(0,ok)==c1-1); assert(seg.prod(0,ok+1)==c1); // 元々ok番目にあったのを消す int c2=cnt[s[ok]-'A']-1; seg.set(ok,0); cnt[s[ok]-'A']--; add+=c2; add%=26; } }