답안 #3837

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
3837 2013-08-31T08:43:17 Z wurikiji Inherited disease (kriii1_I) C++
1 / 1
0 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;
	}

	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;
}
# 결과 실행 시간 메모리 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