Codeforces Round #419 (Div. 1), problem: (B) Karen and Test Solution In C/C++

#include <cstdio>
#include <iostream>
#include <cstring>
#include <cstdlib>
using namespace std;
#define ll long long
const int N=200010;
const ll M=1000000007ll;
ll n,a[N],e[N],re[N];
ll suan(ll x,ll y){
ll t=1;while(y){if(y&1)t=t*x%M;x=x*x%M;y>>=1;}return t;
}
ll work(ll x,ll y){
if(y==0)return 1;
return e[x]*re[x-y]%M*re[y]%M;
}
int main(void){
ll i;
scanf(“%I64d”,&n);
e[0]=1;for(i=1;i<=n;i++)e[i]=e[i-1]*i%M;
re[0]=1;for(i=1;i<=n;i++)re[i]=re[i-1]*suan(i,M-2)%M;
for(i=1;i<=n;i++)scanf(“%I64d”,a+i);
if(n==1){cout<<a[1];return 0;}
if(n%2==1){for(i=1;i<n;i++){if(i%2==1)a[i]=(a[i]+a[i+1])%M;else a[i]=(a[i]-a[i+1]+M)%M;}n–;}
ll ans=0;
for(i=n/2;i>=1;i–){
ans=(ans+a[i*2-1]*work(n/2-1,i-1)%M)%M;
if(n%4==0)ans=(ans-a[i*2]*work(n/2-1,i-1)%M+M)%M;
else ans=(ans+a[i*2]*work(n/2-1,i-1)%M+M)%M;
}
cout<<(ans+M)%M;
return 0;
}

Advertisement

spot_img

Is the Keurig K-Mini...

Keurig K-Mini Long-Term Review: 12 Months of Daily Brewing First-impression...

Can You Make Iced...

How to Brew Refreshing Iced Coffee with the Keurig...

Keurig K-Mini vs Keurig...

Keurig K-Mini vs Keurig K-Slim: Comparing Keurig’s Slimmest Brewers Keurig’s...

Best K-Cup Coffee Pods...

Top Rated K-Cup Coffee Pods for the Keurig K-Mini The...

How to Fix a...

How to Clear Needle Clogs and Fix Slow Flow...

Keurig K-Mini Auto-Off Feature...

Keurig K-Mini Energy Efficiency & Power Consumption Analysis As electricity...

Is the Keurig K-Mini Worth It Long Term? 1-Year Reliability, Durability & Value

Keurig K-Mini Long-Term Review: 12 Months of Daily Brewing First-impression reviews written after three days of testing can tell you how an appliance looks on...

Can You Make Iced Coffee with the Keurig K-Mini? Brew Temperature & Iced Recipes

How to Brew Refreshing Iced Coffee with the Keurig K-Mini During warm summer months, nothing satisfies quite like a tall glass of refreshing iced coffee....

Keurig K-Mini vs Keurig K-Slim: Multi-Cup Reservoir vs Ultra-Compact Brewer

Keurig K-Mini vs Keurig K-Slim: Comparing Keurig’s Slimmest Brewers Keurig’s product catalog features two popular models specifically marketed to space-conscious consumers: the ultra-compact Keurig K-Mini...

Best K-Cup Coffee Pods for Keurig K-Mini: Dark, Medium, Flavored & Decaf Roasts

Top Rated K-Cup Coffee Pods for the Keurig K-Mini The beauty of owning a Keurig K-Mini Single Serve Coffee Maker is universal pod compatibility. Unlike...

How to Fix a Clogged Keurig K-Mini: Exit Needle Cleaning & Troubleshooting Guide

How to Clear Needle Clogs and Fix Slow Flow on the Keurig K-Mini If your Keurig K-Mini suddenly dispenses half a cup of coffee, drips...

Keurig K-Mini Auto-Off Feature and Power Consumption: Energy Efficiency Tested

Keurig K-Mini Energy Efficiency & Power Consumption Analysis As electricity costs rise and consumers increasingly prioritize eco-conscious household appliances, power consumption has become an important...

Keurig K-Mini Dimensions and Cord Storage: Best Compact Coffee Maker for Dorms & RVs

Keurig K-Mini Dimensions & Space-Saving Ergonomics Countertop real estate in modern living spaces has never been tighter. In college dormitories, studio micro-apartments, home office workstations,...

How to Use Reusable K-Cup Coffee Filters with the Keurig K-Mini: Universal Pod Guide

How to Brew Fresh Ground Coffee in Your Keurig K-Mini While pre-packaged K-Cup pods deliver unbeatable morning convenience, they come with two distinct trade-offs: ongoing...

Keurig K-Mini vs Nespresso Vertuo Pop: Compact Coffee Maker Comparison

Keurig K-Mini vs Nespresso Vertuo Pop: The Battle of Compact Brewers Single-serve coffee has evolved into two dominant, competing ecosystems: the versatile, drip-style Keurig K-Cup...