結果
| 問題 | No.3515 Anti EIKO |
| コンテスト | |
| ユーザー |
沙耶花
|
| 提出日時 | 2026-04-24 21:43:08 |
| 言語 | C++17 (gcc 15.2.0 + boost 1.89.0) |
| 結果 |
AC
|
| 実行時間 | 157 ms / 2,000 ms |
| コード長 | 2,118 bytes |
| 記録 | |
| コンパイル時間 | 3,558 ms |
| コンパイル使用メモリ | 286,828 KB |
| 実行使用メモリ | 6,400 KB |
| 最終ジャッジ日時 | 2026-04-24 21:43:15 |
| 合計ジャッジ時間 | 6,740 ms |
|
ジャッジサーバーID (参考情報) |
judge2_0 / judge4_0 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 31 |
ソースコード
#include <stdio.h>
#include <bits/stdc++.h>
#include <atcoder/all>
using namespace atcoder;
using mint = modint998244353;
using namespace std;
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define Inf32 1000000001
#define Inf64 4000000000000000001LL
template <class S,
S (*op0)(S, S),
S (*e0)(),
S (*op1)(S, S),
S (*e1)()
>
struct matrix{
vector<vector<S>> v;
int _h,_w;
matrix(vector<vector<S>> X){
v = X;
_h = X.size();
_w = 0;
if(X.size()>0)_w = X[0].size();
}
matrix(int h,int w){
v.resize(h,vector<S>(w,e0()));
_h = h;
_w = w;
}
void add_element(int from,int to,S x){
v[to][from] = op0(v[to][from],x);
}
matrix e(){
assert(_h==_w);
matrix<S,op0,e0,op1,e1> ret(_h,_w);
for(int i=0;i<_h;i++){
for(int j=0;j<_w;j++){
if(i==j)ret.v[i][j] = e1();
else ret.v[i][j] = e0();
}
}
return ret;
}
matrix &operator*=(const matrix &another){
matrix<S,op0,e0,op1,e1> ret(_h,another._w);
for(int i=0;i<_h;i++){
for(int j=0;j<another._w;j++){
ret.v[i][j] = e0();
for(int k=0;k<_w;k++){
ret.v[i][j] = op0(ret.v[i][j],op1(v[i][k],another.v[k][j]));
}
}
}
v = ret.v;
return (*this);
}
matrix operator*(const matrix &another)const{
return (matrix(*this)*=another);
}
matrix pow(long long cnt){
matrix<S,op0,e0,op1,e1> ret = e();
auto temp = *this;
while(cnt!=0LL){
if((cnt&1)==1){
ret *= temp;
}
temp *= temp;
cnt>>=1;
}
return ret;
}
};
mint op0(mint a,mint b){
return a+b;
}
mint e0(){
return 0;
}
mint op1(mint a,mint b){
return a*b;
}
mint e1(){
return 1;
}
int main(){
long long N,K;
cin>>N>>K;
matrix<mint,op0,e0,op1,e1> M(N*4+2,N*4+2);
rep(i,N*4){
mint v = mint(5).inv();
M.add_element(i,i+1,v);
if(i%4==0){
v = 1-v;
M.add_element(i,0,v);
}
else{
M.add_element(i,0,v*3);
M.add_element(i,1,v);
}
}
M.add_element(N*4,N*4+1,1);
M.add_element(N*4+1,N*4+1,1);
matrix<mint,op0,e0,op1,e1> temp(N*4+2,1);
temp.v[0][0] = 1;
temp = M.pow(K) * temp;
mint ans = temp.v[N*4][0];
cout<<ans.val()<<endl;
return 0;
}
沙耶花