結果

問題 No.1171 Runs in Subsequences
ユーザー eQe
提出日時 2025-09-28 03:40:21
言語 C++23
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 60 ms / 2,000 ms
コード長 3,651 bytes
コンパイル時間 3,546 ms
コンパイル使用メモリ 290,396 KB
実行使用メモリ 7,716 KB
最終ジャッジ日時 2025-09-28 03:40:27
合計ジャッジ時間 5,540 ms
ジャッジサーバーID
(参考情報)
judge2 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 18
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
#if __has_include(<atcoder/all>)
#include<atcoder/modint>
#endif
using namespace std;
#define eb emplace_back
#define fo(i,...) for(auto[i,i##stop,i##step]=for_range<ll>(0,__VA_ARGS__);i<i##stop;i+=i##step)
#define fe(a,e,...) for(auto&&__VA_OPT__([)e __VA_OPT__(,__VA_ARGS__]):a)
#define defpp template<ostream&o=cout>void pp(const auto&...a){[[maybe_unused]]const char*c="";((o<<c<<a,c=" "),...);o<<'\n';}void epp(const auto&...a){pp<cerr>(a...);}
#define entry defpp void main();void main2();}int main(){my::io();my::main();}namespace my{
#define use_ml1000000007 using ml=atcoder::modint1000000007;
namespace my{
auto&operator<<(ostream&o,const atcoder::modint1000000007&x){return o<<(int)x.val();}
void io(){cin.tie(nullptr)->sync_with_stdio(0);cout<<fixed<<setprecision(15);}
using ll=long long;
template<class T>constexpr auto for_range(T s,T b){T a=0;if(s)swap(a,b);return array{a-s,b,1-s*2};}
void lin(auto&...a){(cin>>...>>a);}
auto encode_alphabet(char c){return c-'a';}
template<class A,class B=A>struct pair{
  A a;B b;
  pair()=default;
  pair(A aa,B bb):a(aa),b(bb){}
  auto operator<=>(const pair&)const=default;
};
template<class...A>using pack_back_t=tuple_element_t<sizeof...(A)-1,tuple<A...>>;
}
namespace my{
template<class V>concept vectorial=is_base_of_v<vector<typename remove_cvref_t<V>::value_type>,remove_cvref_t<V>>;
template<class V>constexpr int depth=0;
template<vectorial V>constexpr int depth<V> =depth<typename V::value_type>+1;
template<class T>struct core_t_helper{using type=T;};
template<vectorial V>struct core_t_helper<V>{using type=typename core_t_helper<typename V::value_type>::type;};
template<class T>using core_t=core_t_helper<T>::type;
template<class V>struct vec;
template<int D,class T>struct hvec_helper{using type=vec<typename hvec_helper<D-1,T>::type>;};
template<class T>struct hvec_helper<0,T>{using type=T;};
template<int D,class T>using hvec=hvec_helper<D,T>::type;
template<class V>struct vec:vector<V>{
  static constexpr int D=depth<V>+1;
  using C=core_t<V>;
  using vector<V>::vector;
  vec(const auto&...a)requires(sizeof...(a)>=3){resizes(a...);}
  void resizes(const auto&...a){if constexpr(sizeof...(a)==D){ }else*this=make(a...);}
  static auto make(ll n,const auto&...a){
    if constexpr(sizeof...(a)==1)return vec<C>(n,array{a...}[0]);
    else return vec<decltype(make(a...))>(n,make(a...));
  }
  ll size()const{return vector<V>::size();}
  auto&emplace_back(auto&&...a){vector<V>::emplace_back(std::forward<decltype(a)>(a)...);return*this;}
  auto fold(const auto&f)const{
    pair<C,bool>r{};
    fe(*this,e){
      if constexpr(!vectorial<V>){
        if(r.b)f(r.a,e);
        else r={e,1};
      }else { }

    }
    return r;
  }
  auto max()const{return fold([](auto&a,auto b){if(a<b)a=b;}).a;}
  auto min()const{return fold([](auto&a,auto b){if(b<a)a=b;}).a;}
  auto pos_groups(C M=-1)const{
    assert(min()>=0);
    if(M==-1)M=max();
    vec<vec<int>>res(M+1,0,0);
    fo(i,size())res[(*this)[i]].eb(i);
    return res;
  }
};
template<class...A>requires(sizeof...(A)>=2)vec(const A&...a)->vec<hvec<sizeof...(A)-2,pack_back_t<A...>>>;
auto sin(){string s;lin(s);return s;}
template<class T=ll>auto sinen_alphabet(){vec<T>r;fe(sin(),e)r.eb(encode_alphabet(e));return r;}
}
namespace my{entry
void main(){
  auto s=sinen_alphabet();
  ll N=s.size();

  auto g=s.pos_groups();

  use_ml1000000007
  ml inv2=1/ml(2);

  ml S=0;
  fo(c,g.size()){
    ml su=0;
    ml t=0;
    fe(g[c],i)su+=inv2.pow(i);
    fe(g[c],i){
      su-=inv2.pow(i);
      t+=ml(2).pow(i)*su;
    }
    S+=ml(2).pow(N-1)*t;
  }
  pp(ml(2).pow(N)-1+ml(2).pow(N-1)*(N-2)+1-S);
}}
0