답안 #5761

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
5761 2014-05-16T12:59:45 Z baneling100 생일수 I (GA4_birthday1) C++
100 / 100
84 ms 16712 KB
#include <stdio.h>
#define inf 999999999

int T, N[101], D[1000001], Limit, three[1000001], five[1000001], eight[1000001];

void input(void)
{
    int i;

    scanf("%d",&T);
    for(i=1 ; i<=T ; i++)
    {
        scanf("%d",&N[i]);
        if(Limit<N[i])
            Limit=N[i];
    }
}

void process(void)
{
    int i;

    for(i=1 ; i<=Limit ; i++)
    {
        D[i]=inf;
        if(i>=3)
        {
            if(D[i]>D[i-3]+1)
            {
                D[i]=D[i-3]+1;
                three[i]=three[i-3]+1;
                five[i]=five[i-3];
                eight[i]=eight[i-3];
            }
        }
        if(i>=5)
        {
            if(D[i]>D[i-5]+1)
            {
                D[i]=D[i-5]+1;
                three[i]=three[i-5];
                five[i]=five[i-5]+1;
                eight[i]=eight[i-5];
            }
        }
        if(i>=8)
            if(D[i]>D[i-8]+1)
            {
                D[i]=D[i-8]+1;
                three[i]=three[i-8];
                five[i]=five[i-8];
                eight[i]=eight[i-8]+1;
            }
    }
}

void output(void)
{
    int i, j;

    for(i=1 ; i<=T ; i++)
    {
        if(D[N[i]]==inf)
            printf("-1\n");
        else
        {
            for(j=1 ; j<=three[N[i]] ; j++)
                printf("3");
            for(j=1 ; j<=five[N[i]] ; j++)
                printf("5");
            for(j=1 ; j<=eight[N[i]] ; j++)
                printf("8");
            printf("\n");
        }
    }
}

int main(void)
{
    input();
    process();
    output();

    return 0;

}
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 16712 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 16712 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 16712 KB Output is correct
2 Correct 0 ms 16712 KB Output is correct
3 Correct 0 ms 16712 KB Output is correct
4 Correct 0 ms 16712 KB Output is correct
5 Correct 0 ms 16712 KB Output is correct
6 Correct 0 ms 16712 KB Output is correct
7 Correct 0 ms 16712 KB Output is correct
8 Correct 0 ms 16712 KB Output is correct
9 Correct 0 ms 16712 KB Output is correct
10 Correct 0 ms 16712 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 60 ms 16712 KB Output is correct
2 Correct 68 ms 16712 KB Output is correct
3 Correct 64 ms 16712 KB Output is correct
4 Correct 80 ms 16712 KB Output is correct
5 Correct 68 ms 16712 KB Output is correct
6 Correct 76 ms 16712 KB Output is correct
7 Correct 56 ms 16712 KB Output is correct
8 Correct 48 ms 16712 KB Output is correct
9 Correct 84 ms 16712 KB Output is correct
10 Correct 68 ms 16712 KB Output is correct
11 Correct 76 ms 16712 KB Output is correct
12 Correct 64 ms 16712 KB Output is correct
13 Correct 72 ms 16712 KB Output is correct
14 Correct 80 ms 16712 KB Output is correct
15 Correct 60 ms 16712 KB Output is correct
16 Correct 68 ms 16712 KB Output is correct
17 Correct 72 ms 16712 KB Output is correct
18 Correct 60 ms 16712 KB Output is correct
19 Correct 60 ms 16712 KB Output is correct
20 Correct 64 ms 16712 KB Output is correct
21 Correct 68 ms 16712 KB Output is correct
22 Correct 72 ms 16712 KB Output is correct
23 Correct 84 ms 16712 KB Output is correct
24 Correct 72 ms 16712 KB Output is correct
25 Correct 72 ms 16712 KB Output is correct