Submission #4005

#TimeUsernameProblemLanguageResultExecution timeMemory
4005sjw0687Inherited disease (kriii1_I)C++98
1 / 1
0 ms1672 KiB
#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 timeMemoryGrader output
Fetching results...