結果

問題 No.1696 Nonnil
ユーザー eSeFeSeF
提出日時 2020-10-28 17:41:06
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 130 ms / 3,500 ms
コード長 1,370 bytes
コンパイル時間 2,212 ms
コンパイル使用メモリ 202,884 KB
実行使用メモリ 96,548 KB
最終ジャッジ日時 2023-09-26 15:31:28
合計ジャッジ時間 9,990 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,428 KB
testcase_01 AC 2 ms
5,372 KB
testcase_02 AC 2 ms
5,400 KB
testcase_03 AC 45 ms
95,936 KB
testcase_04 AC 2 ms
5,384 KB
testcase_05 AC 2 ms
5,572 KB
testcase_06 AC 2 ms
5,360 KB
testcase_07 AC 2 ms
5,628 KB
testcase_08 AC 44 ms
96,304 KB
testcase_09 AC 20 ms
28,484 KB
testcase_10 AC 29 ms
32,712 KB
testcase_11 AC 23 ms
24,636 KB
testcase_12 AC 25 ms
32,664 KB
testcase_13 AC 21 ms
24,344 KB
testcase_14 AC 101 ms
90,572 KB
testcase_15 AC 53 ms
36,928 KB
testcase_16 AC 119 ms
96,352 KB
testcase_17 AC 72 ms
87,396 KB
testcase_18 AC 73 ms
63,876 KB
testcase_19 AC 2 ms
5,368 KB
testcase_20 AC 2 ms
5,420 KB
testcase_21 AC 56 ms
80,560 KB
testcase_22 AC 77 ms
78,508 KB
testcase_23 AC 76 ms
74,608 KB
testcase_24 AC 75 ms
70,192 KB
testcase_25 AC 106 ms
85,720 KB
testcase_26 AC 80 ms
86,764 KB
testcase_27 AC 96 ms
95,424 KB
testcase_28 AC 103 ms
74,488 KB
testcase_29 AC 68 ms
84,812 KB
testcase_30 AC 56 ms
70,132 KB
testcase_31 AC 71 ms
89,748 KB
testcase_32 AC 79 ms
93,232 KB
testcase_33 AC 103 ms
80,676 KB
testcase_34 AC 60 ms
82,620 KB
testcase_35 AC 77 ms
85,444 KB
testcase_36 AC 130 ms
96,416 KB
testcase_37 AC 128 ms
96,548 KB
testcase_38 AC 127 ms
96,440 KB
testcase_39 AC 122 ms
96,256 KB
testcase_40 AC 123 ms
95,972 KB
testcase_41 AC 87 ms
45,168 KB
testcase_42 AC 35 ms
90,768 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
using namespace std;
typedef long long ll;
const ll inf = 4611686018427387903LL;
const int MOD=998244353;
ll dp1[2001][2001][2];//縦
ll dp2[2001][2001][2];//斜め
ll mp(ll x,ll n){
  if(n==0)return 1;
  if(n%2==0)return mp((x*x)%MOD,n/2);
  return (x*mp(x,n-1))%MOD;
}
int main()
{
  int N,K,M;
  cin >> N >> K;
  cin >> M;
  vector<int>R(K+1,-1);
  rep(i,M){
    int l,r;
    cin >> l >> r;
    R[r]=max(R[r],l);
  }
  for(int i=K;i>=1;i--){
    bool ok=true;
    for(int j=i-1;j>=0;j--){
      ok&=(R[j]<R[i]);
    }
    if(!ok)R[i]=-1;
  }
  dp1[0][0][0]=dp2[0][0][0]=1;
  for(int j=1;j<=K;j++){
    for(int k=0;k<=K;k++){
      ll nx[2]={0,0};
      if(R[j]!=-1&&k>0){
        int L=R[j];
        for(int l=0;l<2;l++){
          nx[l]+=dp2[j-1][k-1][l^1];
          if(k-(j-L)-1>=0)nx[l]-=dp2[L-1][k-(j-L)-1][l^1];

          if(k-(j-L)-1>=0)nx[l]+=dp1[L-1][k-(j-L)-1][l^1];
          nx[l]%=MOD;
          if(nx[l]<0)nx[l]+=MOD;
        }
      }

      for(int l=0;l<2;l++){
        dp1[j][k][l]=(dp1[j-1][k][l]+nx[l])%MOD;
        dp2[j][k][l]=nx[l];
        if(j-1>=0&&k-1>=0)dp2[j][k][l]+=dp2[j-1][k-1][l];
        dp2[j][k][l]%=MOD;
      }
    }
  }
  ll ans=0;
  for(int i=0;i<=K;i++){
    ans+=(dp1[K][i][0]-dp1[K][i][1]+MOD)*mp(K-i,N);
    ans%=MOD;
  }
  cout << ans << endl;
  return 0;
}
0