結果

問題 No.1239 Multiplication -2
ユーザー eSeFeSeF
提出日時 2020-08-31 15:15:31
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 81 ms / 2,000 ms
コード長 895 bytes
コンパイル時間 2,140 ms
コンパイル使用メモリ 205,040 KB
実行使用メモリ 32,128 KB
最終ジャッジ日時 2024-04-30 15:22:12
合計ジャッジ時間 4,664 ms
ジャッジサーバーID
(参考情報)
judge2 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,812 KB
testcase_01 AC 2 ms
6,940 KB
testcase_02 AC 2 ms
6,940 KB
testcase_03 AC 3 ms
6,944 KB
testcase_04 AC 2 ms
6,940 KB
testcase_05 AC 3 ms
6,944 KB
testcase_06 AC 3 ms
6,944 KB
testcase_07 AC 3 ms
6,940 KB
testcase_08 AC 2 ms
6,940 KB
testcase_09 AC 2 ms
6,940 KB
testcase_10 AC 2 ms
6,944 KB
testcase_11 AC 2 ms
6,948 KB
testcase_12 AC 2 ms
6,940 KB
testcase_13 AC 2 ms
6,940 KB
testcase_14 AC 2 ms
6,940 KB
testcase_15 AC 27 ms
12,364 KB
testcase_16 AC 44 ms
18,432 KB
testcase_17 AC 76 ms
32,128 KB
testcase_18 AC 77 ms
32,128 KB
testcase_19 AC 78 ms
32,128 KB
testcase_20 AC 81 ms
32,128 KB
testcase_21 AC 74 ms
31,488 KB
testcase_22 AC 70 ms
30,336 KB
testcase_23 AC 57 ms
23,424 KB
testcase_24 AC 54 ms
22,528 KB
testcase_25 AC 43 ms
19,968 KB
testcase_26 AC 50 ms
21,120 KB
testcase_27 AC 23 ms
11,136 KB
testcase_28 AC 69 ms
27,904 KB
testcase_29 AC 75 ms
29,952 KB
testcase_30 AC 32 ms
14,464 KB
testcase_31 AC 47 ms
20,224 KB
testcase_32 AC 79 ms
31,872 KB
testcase_33 AC 56 ms
23,168 KB
testcase_34 AC 51 ms
21,760 KB
testcase_35 AC 26 ms
12,544 KB
testcase_36 AC 24 ms
11,444 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int MOD = 998244353;
ll dp[200010][2][3][3];
int main()
{
  int N;
  cin >> N;
  vector<int>A(N);
  for(int i=0;i<N;i++)cin >> A[i];
  dp[0][0][0][0]=1;
  for(int i=0;i<N;i++){
    int neg=A[i]<0?1:0;
    int two=A[i]==0?2:(abs(A[i])==2?1:0);
    for(int j=0;j<2;j++){
      for(int k=0;k<3;k++){
        if(i==0)(dp[i+1][j][k][0]+=dp[i][j][k][0])%=MOD;
        else (dp[i+1][j][k][0]+=2*dp[i][j][k][0])%=MOD;

        (dp[i+1][(j+neg)%2][min(2,k+two)][1]+=dp[i][j][k][0]+dp[i][j][k][1])%=MOD;
        (dp[i+1][(j+neg)%2][min(2,k+two)][2]+=dp[i][j][k][0]+dp[i][j][k][1])%=MOD;

        if(i==N-1)(dp[i+1][j][k][2]+=dp[i][j][k][2])%=MOD;
        else (dp[i+1][j][k][2]+=2*dp[i][j][k][2])%=MOD;
      }
    }
  }
  ll ans=dp[N][1][1][2];
  for(int i=0;i<N-1;i++)(ans*=499122177)%=MOD;
  cout << ans << endl;

  return 0;
}
0