結果
| 問題 |
No.3202 Periodic Alternating Subsequence
|
| コンテスト | |
| ユーザー |
沙耶花
|
| 提出日時 | 2025-07-11 22:18:12 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 86 ms / 2,000 ms |
| コード長 | 1,522 bytes |
| コンパイル時間 | 4,186 ms |
| コンパイル使用メモリ | 260,356 KB |
| 実行使用メモリ | 7,844 KB |
| 最終ジャッジ日時 | 2025-07-11 22:18:20 |
| 合計ジャッジ時間 | 6,857 ms |
|
ジャッジサーバーID (参考情報) |
judge3 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 2 |
| other | AC * 24 |
ソースコード
#include <stdio.h>
#include <atcoder/all>
#include <bits/stdc++.h>
using namespace std;
using namespace atcoder;
using mint = modint1000000007;
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define Inf32 1000000005
#define Inf64 1000000000000000001LL
vector<vector<vector<mint>>> merge(const vector<vector<vector<mint>>>& a, const vector<vector<vector<mint>>>& b) {
vector res(2,vector(2,vector<mint>(3,0)));
rep(i,2){
rep(j,2){
rep(k,3){
res[i][j][k] += a[i][j][k];
res[i][j][k] += b[i][j][k];
}
}
}
rep(i,2){
rep(j,2){
rep(k,2){
rep(l,3){
rep(m,3){
if(l+m>2)continue;
mint v = 1;
if(l==1 && m==1)v = mint(2).inv();
res[i][k][l+m] += a[i][j][l] * b[j^1][k][m] * v;
}
}
}
}
}
return res;
}
int main(){
string s;
cin>>s;
vector dp(2,vector(2,vector<mint>(3,0)));
rep(i,s.size()){
vector ndp(2,vector(2,vector<mint>(3,0)));
ndp[s[i]-'0'][s[i]-'0'][0]++;
ndp[s[i]-'0'][s[i]-'0'][1]+=2;
ndp[s[i]-'0'][s[i]-'0'][2]++;
rep(j,2){
rep(k,2){
rep(l,3){
rep(ll,3){
if(ll<l)continue;
if(k!=s[i]-'0'){
mint v = 1;
if(l==0 && ll==1)v = 2;
ndp[j][k^1][ll] += dp[j][k][l] * v;
}
}
ndp[j][k][l] += dp[j][k][l];
}
}
}
swap(dp,ndp);
}
auto ans = dp;
long long K;
cin>>K;
K--;
rep(i,60){
if((K>>i)&1){
ans = merge(ans,dp);
}
dp = merge(dp,dp);
}
mint ansa = 0;
rep(i,2){
rep(j,2){
ansa +=ans[i][j][2];
}
}
cout<<ansa.val()<<endl;
return 0;
}
沙耶花