답안 #2438

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
2438 2013-07-21T13:44:47 Z rkdrjs0327 생일수 I (GA4_birthday1) C++
100 / 100
676 ms 8696 KB
#include<stdio.h>

struct data
{
    int last,val;
}; data dy[1000001];

void setting()
{
    int i,c1,c2,c3;
    for(i=1; i<=1000000; i++) dy[i].val=dy[i].last=999999999;
    dy[3].last=3; dy[3].val=1;
    dy[5].last=5; dy[5].val=1;
    dy[6].last=3; dy[6].val=2;
    dy[8].last=8; dy[8].val=1;
    for(i=9; i<=1000000; i++){
        c1=dy[i-3].val+1;
        c2=dy[i-5].val+1;
        c3=dy[i-8].val+1;
        if(c1<=c2 && c1<=c3){
            dy[i].last=3;
            dy[i].val=c1;
        }
        else if(c2<=c3 && c2<=c3){
            dy[i].last=5;
            dy[i].val=c2;
        }
        else if(c3<=c1 && c3<=c2){
            dy[i].last=8;
            dy[i].val=c3;
        }
    }
}        
        
void process()
{
    int a,ind;
    scanf("%d",&a);
    ind=a;
    if(dy[ind].val>=999999999) printf("-1");
    else{
        while(ind){
            printf("%d",dy[ind].last);
            ind-=dy[ind].last;
        }
    }
    printf("\n");
}

void input()
{
    int n,i;
    scanf("%d",&n);
    for(i=1; i<=n; i++) process();
}

int main()
{
	setting();
    input();
    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 8696 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 8696 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 8696 KB Output is correct
2 Correct 2 ms 8696 KB Output is correct
3 Correct 3 ms 8696 KB Output is correct
4 Correct 3 ms 8696 KB Output is correct
5 Correct 3 ms 8696 KB Output is correct
6 Correct 3 ms 8696 KB Output is correct
7 Correct 2 ms 8696 KB Output is correct
8 Correct 4 ms 8696 KB Output is correct
9 Correct 3 ms 8696 KB Output is correct
10 Correct 3 ms 8696 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 597 ms 8696 KB Output is correct
2 Correct 588 ms 8696 KB Output is correct
3 Correct 633 ms 8696 KB Output is correct
4 Correct 565 ms 8696 KB Output is correct
5 Correct 591 ms 8696 KB Output is correct
6 Correct 603 ms 8696 KB Output is correct
7 Correct 629 ms 8696 KB Output is correct
8 Correct 639 ms 8696 KB Output is correct
9 Correct 647 ms 8696 KB Output is correct
10 Correct 619 ms 8696 KB Output is correct
11 Correct 583 ms 8696 KB Output is correct
12 Correct 609 ms 8696 KB Output is correct
13 Correct 616 ms 8696 KB Output is correct
14 Correct 667 ms 8696 KB Output is correct
15 Correct 610 ms 8696 KB Output is correct
16 Correct 583 ms 8696 KB Output is correct
17 Correct 592 ms 8696 KB Output is correct
18 Correct 579 ms 8696 KB Output is correct
19 Correct 676 ms 8696 KB Output is correct
20 Correct 573 ms 8696 KB Output is correct
21 Correct 605 ms 8696 KB Output is correct
22 Correct 594 ms 8696 KB Output is correct
23 Correct 576 ms 8696 KB Output is correct
24 Correct 574 ms 8696 KB Output is correct
25 Correct 573 ms 8696 KB Output is correct