結果
問題 | No.1239 Multiplication -2 |
ユーザー |
![]() |
提出日時 | 2021-10-14 19:45:32 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 157 ms / 2,000 ms |
コード長 | 684 bytes |
コンパイル時間 | 4,628 ms |
コンパイル使用メモリ | 259,512 KB |
最終ジャッジ日時 | 2025-01-25 00:27:04 |
ジャッジサーバーID (参考情報) |
judge1 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 34 |
ソースコード
#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 Inf 100000000000000000 int main(){ int N; cin>>N; vector<int> a(N); rep(i,N){ cin>>a[i]; } map<int,mint> dp; dp[1] = 1; mint ans = 0; rep(i,N){ map<int,mint> ndp; for(auto x:dp){ int t = x.first * a[i]; if(t<=-3||t>=3)t = 3; ndp[t] += x.second; } if(i!=0)ndp[a[i]] += mint(2).pow(i-1); ans += ndp[-2] * mint(2).pow(max(0,(N-2)-i)); swap(dp,ndp); //cout<<ans.val()<<endl; } rep(i,N-1)ans /= 2; cout<<ans.val()<<endl; return 0; }