# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
4005 | sjw0687 | Inherited disease (kriii1_I) | C++98 | 0 ms | 1672 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#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 |
---|---|---|---|---|
Fetching results... |