結果
| 問題 |
No.1239 Multiplication -2
|
| コンテスト | |
| ユーザー |
longrun
|
| 提出日時 | 2020-09-25 23:19:55 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 3,737 bytes |
| コンパイル時間 | 2,368 ms |
| コンパイル使用メモリ | 198,572 KB |
| 最終ジャッジ日時 | 2025-01-14 21:37:01 |
|
ジャッジサーバーID (参考情報) |
judge3 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 2 WA * 1 |
| other | AC * 5 WA * 29 |
ソースコード
#include <bits/stdc++.h>
// #include <atcoder/all>
using namespace std;
// using namespace atcoder;
#define rep2(i,m,n) for (int i = (m); i < (n); ++i)
#define rep(i,n) rep2(i,0,n)
typedef long long int ll;
typedef long double ld;
typedef pair<int, int> P;
template<typename T> struct V : vector<T> { using vector<T>::vector; };
V() -> V<int>;
V(size_t) -> V<int>;
template<typename T> V(size_t, T) -> V<T>;
template<typename T> vector<T> make_vec(size_t n, T a) { return vector<T>(n, a); }
template<typename... Ts> auto make_vec(size_t n, Ts... ts) { return vector<decltype(make_vec(ts...))>(n, make_vec(ts...)); }
template<typename T> ostream &operator<<(ostream &os, const vector<T> &v) { for (auto &e : v) os << e << ' '; return os; }
struct fast_ios { fast_ios(){ cin.tie(nullptr); ios::sync_with_stdio(false); cout << fixed << setprecision(20); }; } fast_ios_;
template<typename T> inline bool chmin(T &a, T b) { if (a > b) { a = b; return true; } return false; }
template<typename T> inline bool chmax(T &a, T b) { if (a < b) { a = b; return true; } return false; }
const int INF = 1<<30;
const ll LINF = 1LL<<61;
const ll MOD = 998244353;
struct mint
{
ll x;
mint(ll x = 0) : x(x % MOD) {}
mint& operator+=(const mint rh) { if((x += rh.x) >= MOD) x -= MOD; return *this; }
mint& operator-=(const mint rh) { if((x += MOD-rh.x) >= MOD) x -= MOD; return *this; }
mint& operator*=(const mint rh) { (x *= rh.x) %= MOD; return *this; }
mint operator+(const mint rh) const { return mint(*this) += rh; }
mint operator-(const mint rh) const { return mint(*this) -= rh; }
mint operator*(const mint rh) const { return mint(*this) *= rh; }
mint pow(ll k) const
{
if(!k) return 1;
mint a = x;
mint res = 1;
while(k)
{
if(k & 1) res *= a;
k >>= 1;
a *= a;
}
return res;
}
mint inv() const { return pow(MOD-2); }
mint& operator/=(const mint rh) { return *this *= rh.inv(); }
mint operator/(const mint rh) { return mint(*this) /= rh; }
};
long long mpow(long long x, int k, long long MOD = MOD)
{
long long res = 1;
while(k)
{
if(k & 1) res = (res * x) % MOD;
k >>= 1;
x = (x * x) % MOD;
}
return res;
}
long long modinv(long long a, long long m = MOD)
{
long long b = m, u = 1, v = 0;
while (b) {
long long t = a / b;
a -= t * b; swap(a, b);
u -= t * v; swap(u, v);
}
u %= m;
if (u < 0) u += m;
return u;
}
int main()
{
int n;
cin >> n;
vector<int> a(n);
rep(i,n) cin >> a[i];
vector<mint> dp0(6), dp1(6);
int ofs = 2;
dp1[a[0] + ofs] = 1;
for(int i=1; i<n; i++)
{
vector<mint> dp02(5), dp12(5);
for(int j=-2; j<=2; j++)
{
//区切らない
int nj = j * a[i];
if(abs(nj) <= 2)
{
dp02[nj+ofs] += dp0[j+ofs];
dp12[nj+ofs] += dp1[j+ofs];
}
else
{
dp02[3] += dp0[j+ofs];
dp12[3] += dp1[j+ofs];
}
//区切る
nj = a[i];
if(j == -2)
{
dp02[nj+ofs] += dp0[j+ofs] + dp1[j+ofs];
}
else
{
dp02[nj+ofs] += dp0[j+ofs];
}
dp12[nj+ofs] += dp1[j+ofs];
}
dp02[a[i]+ofs] += dp0[3];
dp12[a[i]+ofs] += dp1[3];
swap(dp0, dp02);
swap(dp1, dp12);
}
mint q = mpow(2, n-1);
q = modinv(q.x);
mint ans = dp1[0];
rep(i,5) ans += dp0[i];
ans *= q;
cout << ans.x << endl;
return 0;
}
longrun