Submission #3831

# Submission time Handle Problem Language Result Execution time Memory
3831 2013-08-31T08:41:41 Z wurikiji Inherited disease (kriii1_I) C++
0 / 1
200 ms 1672 KB
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <string>
#include <vector>
#include <sstream>
#include <iostream>
#include <algorithm>

using namespace std;

const long long divv = 1000000007;

long long child[101];
long long sum[101];
long long dap;
vector<int> ls;

long long gprev(int level)
{
	if( level < 2 ) return 1;
	if( level == 2 ) 
		return ls[0]; 
	long long ret= ((gprev(level-1) - 1) * level) % divv ;
	ret = (ret + ls[level - 2]) %divv;
	return ret;
}
int main(void){
	int d;
	int k;

	child[0] = 0;
	sum[0] = 0;
	child[1] = 1;
	sum[1] = 1;
	for(int i = 2;i < 101;i++)
	{
		child[i] = (child[i-1] * i) % divv ;
		sum[i] = (sum[i-1] + child[i]) %divv;
	}


	while(1){
	ls.clear();
		scanf("%d",&d);

		scanf("%d", &k);
		printf("1\n");
		for(int i = 2 ;i <= d;i++)
		{
			scanf("%d", &k);
			dap = sum[i-1];
			ls.push_back(k);
			dap = ( dap + gprev(i)) %divv;
			printf("%lld\n",dap);
		}
	}
	return 0;
}
# Verdict Execution time Memory Grader output
1 Execution timed out 200 ms 1672 KB Program timed out
2 Halted 0 ms 0 KB -