結果

問題 No.1239 Multiplication -2
ユーザー 沙耶花沙耶花
提出日時 2020-09-25 22:46:34
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,078 bytes
コンパイル時間 2,492 ms
コンパイル使用メモリ 215,032 KB
実行使用メモリ 6,084 KB
最終ジャッジ日時 2023-09-10 15:59:37
合計ジャッジ時間 6,585 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 1 ms
4,380 KB
testcase_03 WA -
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 AC 1 ms
4,380 KB
testcase_10 WA -
testcase_11 WA -
testcase_12 AC 2 ms
4,380 KB
testcase_13 AC 2 ms
4,380 KB
testcase_14 AC 2 ms
4,376 KB
testcase_15 WA -
testcase_16 WA -
testcase_17 AC 149 ms
5,632 KB
testcase_18 WA -
testcase_19 AC 94 ms
5,204 KB
testcase_20 AC 174 ms
5,680 KB
testcase_21 RE -
testcase_22 AC 128 ms
4,908 KB
testcase_23 RE -
testcase_24 WA -
testcase_25 AC 18 ms
4,380 KB
testcase_26 RE -
testcase_27 RE -
testcase_28 RE -
testcase_29 RE -
testcase_30 RE -
testcase_31 RE -
testcase_32 RE -
testcase_33 RE -
testcase_34 RE -
testcase_35 RE -
testcase_36 RE -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <stdio.h>
#include <bits/stdc++.h>
#include <atcoder/modint>
using namespace atcoder;
using mint = modint998244353;
using namespace std;
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define Inf 1000000000
mint ans = 0;

void go(vector<int> a){
	int now = 1;
	
	rep(i,a.size()-1){
		now *= a[i];
		if(now==-2){
			ans += mint(2).pow(i+1).inv();
		}
	}
}

void Go(vector<int> a){
	
	map<int,mint> mp;
	mp[1] = mint(2).inv();
	int t = 1;
	rep(i,a.size()){
		for(auto &x:mp){
			x.second /= 2;
		}
		t *= a[i];
		if(mp.count(-2/t))ans += mp[-2/t];
		mp[t] += mint(2).inv();
	}
	
}

int main(){

	int N;
	cin>>N;
	
	vector<int> a(N);
	rep(i,N){
		cin>>a[i];
	}

	go(a);

	reverse(a.begin(),a.end());
	go(a);
	
	int t = 1;
	rep(i,N){
		t *= a[i];
	}
	if(t==-2){
		ans += mint(2).pow(N-1).inv();
	}
	
	if(N>=3){
		
		a.erase(a.begin());
		a.pop_back();
		
		rep(i,a.size()){
			if(a[i]==0)continue;
			vector<int> T;
			while(i!=a.size()&&a[i]!=0){
				T.push_back(a[i]);
				i++;
			}
			if(T.size()>0){
				Go(T);
			}
		}
		
		
	}
	
	cout<<ans.val()<<endl;

	return 0;
}
0