답안 #2437

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
2437 2013-07-21T13:41:07 Z rkdrjs0327 생일수 I (GA4_birthday1) C++
100 / 100
666 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<=100000; 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 1 ms 8696 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 8696 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 8696 KB Output is correct
2 Correct 4 ms 8696 KB Output is correct
3 Correct 3 ms 8696 KB Output is correct
4 Correct 2 ms 8696 KB Output is correct
5 Correct 3 ms 8696 KB Output is correct
6 Correct 1 ms 8696 KB Output is correct
7 Correct 1 ms 8696 KB Output is correct
8 Correct 3 ms 8696 KB Output is correct
9 Correct 1 ms 8696 KB Output is correct
10 Correct 0 ms 8696 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 593 ms 8696 KB Output is correct
2 Correct 580 ms 8696 KB Output is correct
3 Correct 617 ms 8696 KB Output is correct
4 Correct 549 ms 8696 KB Output is correct
5 Correct 606 ms 8696 KB Output is correct
6 Correct 591 ms 8696 KB Output is correct
7 Correct 639 ms 8696 KB Output is correct
8 Correct 621 ms 8696 KB Output is correct
9 Correct 629 ms 8696 KB Output is correct
10 Correct 614 ms 8696 KB Output is correct
11 Correct 577 ms 8696 KB Output is correct
12 Correct 604 ms 8696 KB Output is correct
13 Correct 601 ms 8696 KB Output is correct
14 Correct 651 ms 8696 KB Output is correct
15 Correct 583 ms 8696 KB Output is correct
16 Correct 586 ms 8696 KB Output is correct
17 Correct 586 ms 8696 KB Output is correct
18 Correct 572 ms 8696 KB Output is correct
19 Correct 666 ms 8696 KB Output is correct
20 Correct 567 ms 8696 KB Output is correct
21 Correct 601 ms 8696 KB Output is correct
22 Correct 590 ms 8696 KB Output is correct
23 Correct 558 ms 8696 KB Output is correct
24 Correct 577 ms 8696 KB Output is correct
25 Correct 591 ms 8696 KB Output is correct