結果

問題 No.1513 simple 門松列 problem
ユーザー たたき@競プロたたき@競プロ
提出日時 2023-09-03 09:59:15
言語 C++23
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 79 ms / 3,000 ms
コード長 1,317 bytes
コンパイル時間 6,042 ms
コンパイル使用メモリ 311,912 KB
実行使用メモリ 4,400 KB
最終ジャッジ日時 2023-09-03 09:59:23
合計ジャッジ時間 7,904 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 2 ms
4,384 KB
testcase_02 AC 79 ms
4,380 KB
testcase_03 AC 1 ms
4,384 KB
testcase_04 AC 1 ms
4,384 KB
testcase_05 AC 2 ms
4,384 KB
testcase_06 AC 2 ms
4,380 KB
testcase_07 AC 2 ms
4,380 KB
testcase_08 AC 2 ms
4,380 KB
testcase_09 AC 2 ms
4,384 KB
testcase_10 AC 1 ms
4,380 KB
testcase_11 AC 2 ms
4,384 KB
testcase_12 AC 1 ms
4,380 KB
testcase_13 AC 2 ms
4,384 KB
testcase_14 AC 78 ms
4,384 KB
testcase_15 AC 79 ms
4,380 KB
testcase_16 AC 78 ms
4,400 KB
testcase_17 AC 49 ms
4,380 KB
testcase_18 AC 17 ms
4,380 KB
testcase_19 AC 2 ms
4,384 KB
testcase_20 AC 11 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
using namespace std;
#include <atcoder/all>
using namespace atcoder;
using mint=modint998244353; //1000000007;
using ll=long long;
using pp=pair<int,int>;
#define sr string 
#define vc vector
#define fi first
#define se second
#define rep(i,n) for(int i=0;i<(int)n;i++)
#define pb push_back
#define all(v) v.begin(),v.end()
#define pque priority_queue
#define bpc(a) __builtin_popcount(a)
int main(){
  int n,k;cin>>n>>k;
  vc dp(k,vc<mint>(k,0)); 
  vc ds(k,vc<mint>(k,0)); 
  rep(i,k)rep(j,k)if(i!=j){
    dp[i][j]=1;
    ds[i][j]=i+j;
  }
  rep(z,n-2){
    vc pre(k,vc<mint>(k,0)); swap(pre,dp);
    vc pres(k,vc<mint>(k,0)); swap(pres,ds);
    vc<mint>up(k,0),down(k,0),ups(k,0),downs(k,0);
    rep(i,k)rep(j,k){
      if(j>i)up[j]+=pre[i][j],ups[j]+=pres[i][j];
      if(j<i)down[j]+=pre[i][j],downs[j]+=pres[i][j];
    }
    //rep(i,k)up[i+1]+=up[i],down[i+1]+=down[i];
    rep(i,k)rep(j,k){
      if(j>i){
        dp[i][j]=down[i]-pre[j][i];
        ds[i][j]=downs[i]-pres[j][i]+dp[i][j]*j;
      }
      if(j<i){
        dp[i][j]=up[i]-pre[j][i];
        ds[i][j]=ups[i]-pres[j][i]+dp[i][j]*j;
      }
    }
  }
  mint ans1=0,ans2=0;
  //rep(i,k)rep(j,k)cout<<i<<' '<<j<<' '<<ds[i][j].val()<<"\n";
  rep(i,k)rep(j,k)ans1+=dp[i][j],ans2+=ds[i][j];
  cout<<ans1.val()<<' '<<ans2.val();
}
0