結果

問題 No.1239 Multiplication -2
ユーザー furafura
提出日時 2020-10-20 16:23:15
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 173 ms / 2,000 ms
コード長 1,877 bytes
コンパイル時間 2,202 ms
コンパイル使用メモリ 210,968 KB
実行使用メモリ 14,112 KB
最終ジャッジ日時 2023-09-28 13:42:52
合計ジャッジ時間 7,362 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 2 ms
4,376 KB
testcase_03 AC 3 ms
4,380 KB
testcase_04 AC 3 ms
4,380 KB
testcase_05 AC 3 ms
4,376 KB
testcase_06 AC 2 ms
4,376 KB
testcase_07 AC 2 ms
4,376 KB
testcase_08 AC 2 ms
4,376 KB
testcase_09 AC 2 ms
4,380 KB
testcase_10 AC 1 ms
4,376 KB
testcase_11 AC 1 ms
4,376 KB
testcase_12 AC 1 ms
4,380 KB
testcase_13 AC 2 ms
4,376 KB
testcase_14 AC 1 ms
4,376 KB
testcase_15 AC 51 ms
7,016 KB
testcase_16 AC 97 ms
9,360 KB
testcase_17 AC 61 ms
4,376 KB
testcase_18 AC 61 ms
4,376 KB
testcase_19 AC 81 ms
5,368 KB
testcase_20 AC 65 ms
4,380 KB
testcase_21 AC 144 ms
11,240 KB
testcase_22 AC 166 ms
12,520 KB
testcase_23 AC 96 ms
8,316 KB
testcase_24 AC 122 ms
10,492 KB
testcase_25 AC 168 ms
14,112 KB
testcase_26 AC 110 ms
9,384 KB
testcase_27 AC 32 ms
5,276 KB
testcase_28 AC 127 ms
9,696 KB
testcase_29 AC 141 ms
10,224 KB
testcase_30 AC 57 ms
6,712 KB
testcase_31 AC 88 ms
8,620 KB
testcase_32 AC 173 ms
12,340 KB
testcase_33 AC 111 ms
9,352 KB
testcase_34 AC 106 ms
9,088 KB
testcase_35 AC 44 ms
6,136 KB
testcase_36 AC 39 ms
5,736 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>

#define rep(i,n) for(int i=0;i<(n);i++)

using namespace std;

class mint{
	static const int MOD=998244353;
	int x;
public:
	mint():x(0){}
	mint(long long y){ x=y%MOD; if(x<0) x+=MOD; }

	mint& operator+=(const mint& m){ x+=m.x; if(x>=MOD) x-=MOD; return *this; }
	mint& operator-=(const mint& m){ x-=m.x; if(x<   0) x+=MOD; return *this; }
	mint& operator*=(const mint& m){ x=1LL*x*m.x%MOD; return *this; }
	mint& operator/=(const mint& m){ return *this*=inverse(m); }
	mint operator+(const mint& m)const{ return mint(*this)+=m; }
	mint operator-(const mint& m)const{ return mint(*this)-=m; }
	mint operator*(const mint& m)const{ return mint(*this)*=m; }
	mint operator/(const mint& m)const{ return mint(*this)/=m; }
	mint operator-()const{ return -x; }

	friend mint inverse(const mint& m){
		int a=m.x,b=MOD,u=1,v=0;
		while(b>0){ int t=a/b; a-=t*b; swap(a,b); u-=t*v; swap(u,v); }
		return u;
	}

	friend istream& operator>>(istream& is,mint& m){ long long t; is>>t; m=t; return is; }
	friend ostream& operator<<(ostream& os,const mint& m){ return os<<m.x; }
	int to_int()const{ return x; }
};

mint operator+(long long x,const mint& m){ return mint(x)+m; }
mint operator-(long long x,const mint& m){ return mint(x)-m; }
mint operator*(long long x,const mint& m){ return mint(x)*m; }
mint operator/(long long x,const mint& m){ return mint(x)/m; }

mint pow(mint m,long long k){
	mint res=1;
	for(;k>0;k>>=1,m*=m) if(k&1) res*=m;
	return res;
}

bool operator<(const mint& x,const mint& y){ return x.to_int()<y.to_int(); }

int main(){
	int n; scanf("%d",&n);
	vector<int> a(n);
	rep(i,n){
		scanf("%d",&a[i]);
		if(a[i]==0) a[i]=3;
	}

	mint ans=0;
	map<mint,mint> f;
	f[1]=1;
	mint cum=1;
	rep(i,n){
		cum*=a[i];
		f[cum]+=pow(mint(2),i);
		ans+=f[cum/(-2)]*pow(mint(2),i==n-1?0:n-i-2);
	}
	ans/=pow(mint(2),n-1);
	cout<<ans<<'\n';

	return 0;
}
0