답안 #4314

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
4314 2013-09-12T10:07:27 Z zorrapower Inherited disease (kriii1_I) C++
0 / 1
200 ms 1088 KB
#include<stdio.h>

void get_N_generationArea(long long n,long long *start, long long *end);
long long Factorial(long long n);
long long getResult(long long n, long long *start, long long *end);

long long Array[100];
long long n;

int main(void){
	long long start,end;
	get_N_generationArea(2, &start, &end);

	scanf("%d", &n);

	for(long long i=0; i<n; i++)
		scanf("%d", &Array[i]);

	for(long long i=1; i<=n; i++){
		printf("%d\n", getResult(i, &start, &end)%1000000007);
	}
	while(true);
	return 0;
}

void get_N_generationArea(long long n,long long *start, long long *end){
	*start=0;
	*end=0;
	for(long long i=1; i<=n; i++){
		*end+=Factorial(i)%1000000007;
		*start=(*end-Factorial(i)+1)%1000000007;
	}
}

long long Factorial(long long n){
	long long result=1;
	for(long long i=1; i<=n; i++){
		result=(result*i)%1000000007;
	}
	return result;
}

long long getResult(long long generation, long long *start, long long *end){
	long long area;
	get_N_generationArea(generation, start, end);
	area=*end-*start+1;
	for(long long i=0; i<generation; i++){
		area/=i+1;
		*start+=area*(Array[i]-1);
		*end=*start+area-1;

	}
	return *start;
}
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 200 ms 1088 KB Program timed out
2 Halted 0 ms 0 KB -