Submission #5898532


Source Code Expand

Copy
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <algorithm>
using namespace std;
const int maxn = 100100;
const int mod = 1e9 + 7;
long long power(long long x, long long k)
{
	long long ans = 1;
	while(k)
	{
		if(k & 1)
			(ans *= x) %= mod;
		k >>= 1;
		(x *= x) %= mod;
	}
	return ans;
}
int n;
long long fac[maxn], invfac[maxn], inv[maxn], hinv[maxn];
void init()
{
	fac[0] = 1;
	for(int i = 1; i <= n; i ++)
		fac[i] = fac[i - 1] * i % mod;
	invfac[n] = power(fac[n], mod - 2);
	for(int i = n - 1; i >= 1; i --)
		invfac[i] = invfac[i + 1] * (i + 1) % mod;
	for(int i = 1; i <= n; i ++)
		inv[i] = fac[i - 1] * invfac[i] % mod;
	hinv[0] = 0;
	for(int i = 1; i <= n; i ++)
		hinv[i] = (hinv[i - 1] + inv[i]) % mod;
}
long long ans = 0;
int main()
{
	std::ios::sync_with_stdio(false);
	cin >> n;
	init();	
	for(int i = 1; i <= n; i ++)
	{
		long long a;
		cin >> a;
		(ans += a * (hinv[i] + hinv[n - i + 1] - 1)) %= mod;
	}
	cout << ans * fac[n] % mod << endl;
	return 0;
}

Submission Info

Submission Time
Task B - Removing Blocks
User zhangyuxi
Language C++14 (GCC 5.4.1)
Score 600
Code Size 1080 Byte
Status
Exec Time 14 ms
Memory 3456 KB

Test Cases

Set Name Score / Max Score Test Cases
Sample 0 / 0 sample-01.txt, sample-02.txt, sample-03.txt
All 600 / 600 sample-01.txt, sample-02.txt, sample-03.txt, sample-01.txt, sample-02.txt, sample-03.txt, subtask01-01.txt, subtask01-02.txt, subtask01-03.txt, subtask01-04.txt, subtask01-05.txt, subtask01-06.txt, subtask01-07.txt, subtask01-08.txt, subtask01-09.txt, subtask01-10.txt, subtask01-11.txt, subtask01-12.txt, subtask01-13.txt
Case Name Status Exec Time Memory
sample-01.txt 1 ms 256 KB
sample-02.txt 1 ms 256 KB
sample-03.txt 1 ms 256 KB
subtask01-01.txt 1 ms 256 KB
subtask01-02.txt 12 ms 2560 KB
subtask01-03.txt 9 ms 2048 KB
subtask01-04.txt 11 ms 2560 KB
subtask01-05.txt 4 ms 1024 KB
subtask01-06.txt 6 ms 1536 KB
subtask01-07.txt 4 ms 1024 KB
subtask01-08.txt 14 ms 3456 KB
subtask01-09.txt 14 ms 3456 KB
subtask01-10.txt 14 ms 3456 KB
subtask01-11.txt 14 ms 3456 KB
subtask01-12.txt 14 ms 3456 KB
subtask01-13.txt 14 ms 3328 KB