結果

問題 No.1681 +-*
ユーザー inksamuraiinksamurai
提出日時 2021-09-17 22:42:05
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 44 ms / 2,000 ms
コード長 1,866 bytes
コンパイル時間 1,425 ms
コンパイル使用メモリ 166,388 KB
実行使用メモリ 4,688 KB
最終ジャッジ日時 2023-09-12 08:42:11
合計ジャッジ時間 3,397 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 1 ms
4,384 KB
testcase_03 AC 1 ms
4,376 KB
testcase_04 AC 2 ms
4,376 KB
testcase_05 AC 35 ms
4,572 KB
testcase_06 AC 35 ms
4,524 KB
testcase_07 AC 35 ms
4,568 KB
testcase_08 AC 43 ms
4,512 KB
testcase_09 AC 44 ms
4,636 KB
testcase_10 AC 44 ms
4,632 KB
testcase_11 AC 44 ms
4,512 KB
testcase_12 AC 44 ms
4,612 KB
testcase_13 AC 22 ms
4,376 KB
testcase_14 AC 44 ms
4,688 KB
testcase_15 AC 1 ms
4,380 KB
testcase_16 AC 1 ms
4,376 KB
testcase_17 AC 44 ms
4,608 KB
testcase_18 AC 43 ms
4,512 KB
testcase_19 AC 44 ms
4,512 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
//eolibraries
#define lnf 3999999999999999999
#define inf 999999999
#define fi first
#define se second
#define pb push_back
#define all(c) (c).begin(),(c).end()
#define sz(c) (int)(c).size()
#define make_unique(a) sort(all(a)),a.erase(unique(all(a)),a.end());
#define rep(i,n) for(int i=0;i<n;i++)
#define drep(i,n) for(int i=n-1;i>=0;i--)
#define crep(i,x,n) for(int i=x;i<n;i++)
#define vec(...) vector<__VA_ARGS__>
#define _3E8xdS5 ios_base::sync_with_stdio(false),cin.tie(0),cout.tie(0)
//eodefine
using namespace std;
typedef long long ll;
typedef long double ld;
using pii=pair<int,int>;
using vi=vec(int);
using vll=vec(ll);
const int mxn=12000;

//snuke's modular int
template <ll mod>
struct modularint{
	ll x;
	modularint(ll x=0):x(x%mod){}
	modularint& operator+=(const modularint a){
		if ((x += a.x) >= mod) x -= mod;
		return *this;
	}
	modularint& operator-=(const modularint a){
		if ((x += mod-a.x) >= mod) x -= mod;
		return *this;
	}
	modularint& operator*=(const modularint a){
		(x *= a.x) %= mod;
		return *this;
	}
	modularint operator+(const modularint a)const{
		modularint res(*this);
		return res+=a;
	}
	modularint operator-(const modularint a)const{
		modularint res(*this);
		return res-=a;
	}
	modularint operator*(const modularint a)const{
		modularint res(*this);
		return res*=a;
	}
	modularint pow(ll n)const{
		modularint res=1,x(*this);
		while(n){
			if(n&1)res*=x;
			x*=x;
			n>>=1;
		}
		return res;
	}
	modularint inv()const{
		return pow(mod-2);
	}
};
using mint=modularint<1000000007>;

int main(){
_3E8xdS5;
	int n;
	cin>>n;
	vll a(n);
	rep(i,n){
		cin>>a[i];
	}
	mint ans=0;
	ans+=mint(a[0])*mint(2)*mint(3).pow(n-2);
	mint prod=a[0];
	crep(i,1,n){
		prod*=mint(a[i]);
		if(i==n-1){
			ans+=prod;
		}else{
			ans+=prod*mint(2)*mint(3).pow(n-i-2);
		}
	}
	printf("%lld\n",ans.x);
//	
	return 0;
}
0