Submission #4005

# Submission time Handle Problem Language Result Execution time Memory
4005 2013-08-31T09:57:02 Z sjw0687 Inherited disease (kriii1_I) C++
1 / 1
0 ms 1672 KB
#include <cstdio>
#include <iostream>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <climits>
#include <algorithm>
#include <utility>
#include <string>
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <queue>
#include <stack>
#include <bitset>
using namespace std;

typedef long long llong;
const llong MOD = 1000000007;

llong fact[101];
llong sumFact[101];

llong minu(llong a, llong b)
{
	llong ret = a - b;
	while( ret < 0 )
		ret += MOD;
	return ret;
}

int main(void)
{
	int n;
	cin >> n;
	int child[101];
	for(int i=1; i<=n; i++)
		cin >> child[i];

	fact[0] = 1, sumFact[0] = 0;
	for(int i=1; i<=n; i++) {
		fact[i] = fact[i-1] * i % MOD;
		sumFact[i] = (sumFact[i-1] + fact[i]) % MOD;
	}

	cout << "1" << endl;
	llong preFirst = 1; llong preNum = 1; llong curNum;
	for(int d=2; d<=n; d++) {
		llong first = (sumFact[d-1] + 1) % MOD;
		//cout << "preFirst: " << preFirst << endl;
		//cout << "preNum: " << preNum << endl;
		curNum = ((minu(first, 1) + (minu(preNum, preFirst) * d % MOD)) % MOD + child[d]) % MOD;
		preFirst = first;
		preNum = curNum;
		cout << curNum << endl;
	}

	return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 1672 KB Output is correct
2 Correct 0 ms 1672 KB Output is correct
3 Correct 0 ms 1672 KB Output is correct
4 Correct 0 ms 1672 KB Output is correct
5 Correct 0 ms 1672 KB Output is correct
6 Correct 0 ms 1672 KB Output is correct
7 Correct 0 ms 1672 KB Output is correct
8 Correct 0 ms 1672 KB Output is correct
9 Correct 0 ms 1672 KB Output is correct
10 Correct 0 ms 1672 KB Output is correct
11 Correct 0 ms 1672 KB Output is correct
12 Correct 0 ms 1672 KB Output is correct
13 Correct 0 ms 1672 KB Output is correct
14 Correct 0 ms 1672 KB Output is correct
15 Correct 0 ms 1672 KB Output is correct
16 Correct 0 ms 1672 KB Output is correct
17 Correct 0 ms 1672 KB Output is correct
18 Correct 0 ms 1672 KB Output is correct
19 Correct 0 ms 1672 KB Output is correct
20 Correct 0 ms 1672 KB Output is correct