結果

問題 No.1239 Multiplication -2
ユーザー furafura
提出日時 2020-10-20 16:35:27
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 856 ms / 2,000 ms
コード長 2,018 bytes
コンパイル時間 2,164 ms
コンパイル使用メモリ 213,372 KB
実行使用メモリ 15,428 KB
最終ジャッジ日時 2023-09-28 13:43:12
合計ジャッジ時間 12,288 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 2 ms
4,380 KB
testcase_03 AC 5 ms
4,380 KB
testcase_04 AC 5 ms
4,380 KB
testcase_05 AC 5 ms
4,376 KB
testcase_06 AC 3 ms
4,376 KB
testcase_07 AC 3 ms
4,380 KB
testcase_08 AC 2 ms
4,380 KB
testcase_09 AC 2 ms
4,380 KB
testcase_10 AC 3 ms
4,380 KB
testcase_11 AC 2 ms
4,380 KB
testcase_12 AC 2 ms
4,380 KB
testcase_13 AC 3 ms
4,376 KB
testcase_14 AC 2 ms
4,380 KB
testcase_15 AC 201 ms
7,964 KB
testcase_16 AC 412 ms
10,756 KB
testcase_17 AC 59 ms
5,056 KB
testcase_18 AC 59 ms
5,060 KB
testcase_19 AC 167 ms
6,608 KB
testcase_20 AC 67 ms
5,056 KB
testcase_21 AC 648 ms
12,544 KB
testcase_22 AC 743 ms
13,764 KB
testcase_23 AC 368 ms
9,524 KB
testcase_24 AC 501 ms
11,504 KB
testcase_25 AC 856 ms
15,428 KB
testcase_26 AC 450 ms
10,488 KB
testcase_27 AC 108 ms
6,300 KB
testcase_28 AC 479 ms
10,880 KB
testcase_29 AC 570 ms
11,236 KB
testcase_30 AC 221 ms
7,988 KB
testcase_31 AC 413 ms
9,964 KB
testcase_32 AC 799 ms
13,548 KB
testcase_33 AC 475 ms
10,692 KB
testcase_34 AC 403 ms
10,248 KB
testcase_35 AC 158 ms
7,208 KB
testcase_36 AC 138 ms
6,972 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; }

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

int n,a[200000];
mint two[200000];

mint solve(int p){
	rep(i,n) if(a[i]==0 || abs(a[i])>2) a[i]=p;

	mint res=0,cum=1;
	map<mint,mint> f;
	f[1]=1;
	rep(i,n){
		cum*=a[i];
		f[cum]+=two[i];
		res+=f[cum/(-2)]*two[i==n-1?0:n-i-2];
	}
	return res/two[n-1];
}

int main(){
	scanf("%d",&n);
	rep(i,n) scanf("%d",&a[i]);

	two[0]=1;
	rep(i,n-1) two[i+1]=two[i]*2;

	map<mint,int> f;
	++f[solve(3)];
	++f[solve(5)];
	++f[solve(7)];
	++f[solve(11)];
	++f[solve(13)];

	mint ans;
	int best=0;
	for(auto [x,c]:f) if(c>best) ans=x, best=c;
	cout<<ans<<'\n';

	return 0;
}
0