結果
| 問題 |
No.1239 Multiplication -2
|
| コンテスト | |
| ユーザー |
carrot46
|
| 提出日時 | 2020-09-25 22:39:00 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 109 ms / 2,000 ms |
| コード長 | 2,885 bytes |
| コンパイル時間 | 1,952 ms |
| コンパイル使用メモリ | 180,024 KB |
| 実行使用メモリ | 5,376 KB |
| 最終ジャッジ日時 | 2024-06-28 07:02:02 |
| 合計ジャッジ時間 | 4,611 ms |
|
ジャッジサーバーID (参考情報) |
judge4 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 34 |
ソースコード
#include <bits/stdc++.h>
//#include <chrono>
//#pragma GCC optimize("Ofast")
using namespace std;
#define reps(i,s,n) for(int i = s; i < n; i++)
#define rep(i,n) reps(i,0,n)
#define Rreps(i,n,e) for(int i = n - 1; i >= e; --i)
#define Rrep(i,n) Rreps(i,n,0)
#define ALL(a) a.begin(), a.end()
#define fi first
#define se second
using ll = long long;
using vec = vector<ll>;
using mat = vector<vec>;
ll N,M,H,W,Q,K,A,B;
string S;
typedef pair<ll, ll> P;
const ll INF = (1LL<<58);
template <unsigned long long mod > class modint{
public:
ll x;
constexpr modint(){x = 0;}
constexpr modint(ll _x) : x((_x < 0 ? ((_x += (LLONG_MAX / mod) * mod) < 0 ? _x + (LLONG_MAX / mod) * mod : _x) : _x)%mod){}
constexpr void set_raw(ll _x){
//_x in [0, mod)
x = _x;
}
constexpr modint operator-(){
return x == 0 ? 0 : mod - x;
}
constexpr modint& operator+=(const modint& a){
if((x += a.x) >= mod) x -= mod;
return *this;
}
constexpr modint operator+(const modint& a) const{
return modint(*this) += a;
}
constexpr modint& operator-=(const modint& a){
if((x -= a.x) < 0) x += mod;
return *this;
}
constexpr modint operator-(const modint& a) const{
return modint(*this) -= a;
}
constexpr modint& operator*=(const modint& a){
(x *= a.x)%=mod;
return *this;
}
constexpr modint operator*(const modint& a) const{
return modint(*this) *= a;
}
constexpr modint pow(unsigned long long pw) const{
modint res(1), comp(*this);
while(pw){
if(pw&1) res *= comp;
comp *= comp;
pw >>= 1;
}
return res;
}
//以下、modが素数のときのみ
constexpr modint inv() const{
return modint(*this).pow(mod - 2);
}
constexpr modint& operator/=(const modint &a){
(x *= a.inv().x)%=mod;
return *this;
}
constexpr modint operator/(const modint &a) const{
return modint(*this) /= a;
}
};
#define mod1 998244353
using mint = modint<mod1>;
ostream& operator<<(ostream& os, const mint& a){
os << a.x;
return os;
}
using vm = vector<mint>;
int main() {
cin>>N;
vec a(N);
rep(i, N) cin>>a[i];
map<int, mint> lst, nxt;
lst[1] = 1;
mint res(0);
rep(i, N){
for(int j = -2; j <= 2; ++j){
int nj = j * a[i];
if(abs(nj) > 2) nj = 0;
nxt[nj] += lst[j];
if(i != 0) {
if (j == -2) res += lst[j] * mint(2).pow(max(0LL, N - 1 - i));
nxt[a[i]] += lst[j];
}
}
/*
cout<<res<<endl;
reps(j, -2, 3) cout<<nxt[j]<<' ';
cout<<endl;
*/
swap(lst, nxt);
nxt.clear();
}
res += lst[-2];
cout<<res * mint(2).pow(mod1 - N)<<endl;
}
carrot46