結果

問題 No.1847 Good Sequence
ユーザー 👑 potato167potato167
提出日時 2021-12-07 02:53:43
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 83 ms / 3,000 ms
コード長 1,796 bytes
コンパイル時間 2,847 ms
コンパイル使用メモリ 219,704 KB
実行使用メモリ 6,676 KB
最終ジャッジ日時 2024-04-08 21:33:38
合計ジャッジ時間 4,998 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,676 KB
testcase_01 AC 2 ms
6,676 KB
testcase_02 AC 3 ms
6,676 KB
testcase_03 AC 2 ms
6,676 KB
testcase_04 AC 2 ms
6,676 KB
testcase_05 AC 2 ms
6,676 KB
testcase_06 AC 2 ms
6,676 KB
testcase_07 AC 2 ms
6,676 KB
testcase_08 AC 2 ms
6,676 KB
testcase_09 AC 3 ms
6,676 KB
testcase_10 AC 2 ms
6,676 KB
testcase_11 AC 2 ms
6,676 KB
testcase_12 AC 2 ms
6,676 KB
testcase_13 AC 2 ms
6,676 KB
testcase_14 AC 2 ms
6,676 KB
testcase_15 AC 2 ms
6,676 KB
testcase_16 AC 2 ms
6,676 KB
testcase_17 AC 3 ms
6,676 KB
testcase_18 AC 2 ms
6,676 KB
testcase_19 AC 2 ms
6,676 KB
testcase_20 AC 2 ms
6,676 KB
testcase_21 AC 41 ms
6,676 KB
testcase_22 AC 8 ms
6,676 KB
testcase_23 AC 2 ms
6,676 KB
testcase_24 AC 2 ms
6,676 KB
testcase_25 AC 14 ms
6,676 KB
testcase_26 AC 2 ms
6,676 KB
testcase_27 AC 4 ms
6,676 KB
testcase_28 AC 10 ms
6,676 KB
testcase_29 AC 2 ms
6,676 KB
testcase_30 AC 2 ms
6,676 KB
testcase_31 AC 19 ms
6,676 KB
testcase_32 AC 12 ms
6,676 KB
testcase_33 AC 44 ms
6,676 KB
testcase_34 AC 2 ms
6,676 KB
testcase_35 AC 3 ms
6,676 KB
testcase_36 AC 38 ms
6,676 KB
testcase_37 AC 29 ms
6,676 KB
testcase_38 AC 2 ms
6,676 KB
testcase_39 AC 2 ms
6,676 KB
testcase_40 AC 83 ms
6,676 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
using std::cout;
using std::cin;
using std::endl;
using ll=long long;
const ll mod=1e9+7;
#define rep(i,a) for (ll i=0;i<a;i++)

//retrun x^{y}
ll my_pow(ll x,ll y){
	if(x==0) return 0;
	if(y==0) return 1;
	if(y%2) return (x*my_pow(x,y-1))%mod;
	return my_pow((x*x)%mod,y/2);
}

vector<vector<ll>> v_mul(vector<vector<ll>> a,vector<vector<ll>> b){
  int A=a.size(),B=a[0].size(),C=b.size(),D=b[0].size();
  vector<vector<ll>> r(A,vector<ll>(D));
  for(int i=0;i<A;i++){
    for(int k=0;k<B;k++){
      for(int j=0;j<D;j++){
        r[i][j]+=(a[i][k]*b[k][j])%mod;
		r[i][j]%=mod;
      }
    }
  }
  return r;
}
vector<vector<ll>> v_jyo(vector<vector<ll>> a,int64_t N){
  int m=a.size();
  ll H=1;
  vector<vector<ll>> r(m,vector<ll>(m,0));
  for(int i=0;i<m;i++){
    r[i][i]=1;
  }
  while(N>0){
    H*=2;
    if(N%H){
      N-=(H/2);
      r=v_mul(r,a);
    }
    a=v_mul(a,a);
  }
  return r;
}

ll MAX_L=1e18;
int MAX_N=15;

//  rainy ~ 雨に打たれて ~
int main() {
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	
	ll L,N,M;
	cin>>L>>N>>M;
	vector<int> p(M);
	set<int> s;
	int len=0;
	rep(i,M){
		cin>>p[i];
		len+=p[i]+1;
	}

	sort(p.begin(),p.end());
	assert(1<=L&&L<=MAX_L);
	assert(1<=N&&0<=M&&M<=N&&N<=MAX_N);
	rep(i,M-1) assert(p[i]!=p[i+1]);

	len++;
	vector<vector<ll>> base(len,vector<ll>(len));
	int tmp=0;
	for(auto x:p){
		rep(i,len){
			if(i<tmp||tmp+x+1<=i) base[i][tmp]=1;
		}
		rep(i,x) base[tmp][tmp+1]=1,tmp++;
		s.insert(tmp-1);
		base[tmp][tmp]=1;
		tmp++;
	}
	rep(i,len) base[i][tmp]=N-M;
	tmp=0;
	for(auto x:p){
		rep(i,len){
			if(i!=x+tmp) base[tmp+x-1][i]=0;
		}
		tmp+=x+1;
	}
	auto val=v_jyo(base,L);
	ll ans=my_pow(N,L);
	rep(i,len){
		if(!s.count(i)) ans-=val[len-1][i];
	}
	cout<<(ans%mod+mod)%mod<<"\n";
}
0