Educational Codeforces Round 47 (Rated for Div. 2) :E. Intercity Travelling

时间:2024-10-29 21:05:26

题目链接:http://codeforces.com/contest/1009/problem/E

解题心得:

#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e6+;
const long long MOD = ;
typedef long long ll;
ll num[maxn], pow2[maxn];
ll n; void get_pow2(){
pow2[] = ;
for(int i=;i<=n;i++)
pow2[i] = (pow2[i-] * ) % MOD;
} void init() {
scanf("%lld",&n);
for(ll i=;i<=n;i++) {
scanf("%lld",&num[i]);
}
get_pow2();
} void solve(){
ll ans = ;
for(ll i=;i<=n;i++){
ll temp;
if(i == n)
temp = ;
else
temp = pow2[n-i] + pow2[n-i-]*(n-i);
temp %= MOD;
ans += temp*num[i];
ans %= MOD;
}
printf("%lld\n",ans);
} int main() {
init();
solve();
return ;
}