답안 #4295

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

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

int Array[100];
int n;

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

	scanf("%d", &n);

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

	for(int i=1; i<=n; i++){
		printf("%d\n", getResult(i, &start, &end)%1000000007);
	}

	return 0;
}

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

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

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

	}
	return *start;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 1088 KB Output is correct
2 Incorrect 0 ms 1088 KB Output isn't correct
3 Halted 0 ms 0 KB -