Submission #17523

# Submission time Handle Problem Language Result Execution time Memory
17523 2015-12-25T13:50:33 Z atomzeno 생일수 I (GA4_birthday1) C++
100 / 100
127 ms 4988 KB
#include<stdio.h>
#define MX 1000001
int A[MX],B[3]={3,5,8},a,num[3];
int main(){
    int i,j,n;
    //freopen("input.txt","r",stdin);
    //freopen("output.txt","w",stdout);
    A[0]=0;
    for(i=1;i<MX;i++){A[i]=MX+1;}
    for(i=1;i<MX;i++){
        for(j=0;j<3;j++){
            if(i>=B[j]&&(A[i-B[j]]+1)<A[i]){
                A[i]=(A[i-B[j]]+1);
            }
        }
    }
    scanf("%d",&n);
    for(i=0;i<n;i++){
        scanf("%d",&a);
        if(A[a]==MX+1){printf("-1\n");}
        else{
            for(j=0;j<3;j++){num[j]=0;}
            for(j=a;j!=0;){
                if(j>=8&&(A[j-8]+1)==A[j]){
                    num[2]++;
                    j-=8;\
                }
                else if(j>=5&&(A[j-5]+1)==A[j]){
                    num[1]++;
                    j-=5;
                }
                else{
                    num[0]++;
                    j-=3;
                }
            }
            for(j=0;j<num[0];j++){printf("3");}
            for(j=0;j<num[1];j++){printf("5");}
            for(j=0;j<num[2];j++){printf("8");}
            printf("\n");
        }
    }
}
# Verdict Execution time Memory Grader output
1 Correct 7 ms 4988 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 7 ms 4988 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 4988 KB Output is correct
2 Correct 7 ms 4988 KB Output is correct
3 Correct 8 ms 4988 KB Output is correct
4 Correct 8 ms 4988 KB Output is correct
5 Correct 3 ms 4988 KB Output is correct
6 Correct 7 ms 4988 KB Output is correct
7 Correct 7 ms 4988 KB Output is correct
8 Correct 7 ms 4988 KB Output is correct
9 Correct 7 ms 4988 KB Output is correct
10 Correct 7 ms 4988 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 108 ms 4988 KB Output is correct
2 Correct 88 ms 4988 KB Output is correct
3 Correct 99 ms 4988 KB Output is correct
4 Correct 103 ms 4988 KB Output is correct
5 Correct 97 ms 4988 KB Output is correct
6 Correct 86 ms 4988 KB Output is correct
7 Correct 88 ms 4988 KB Output is correct
8 Correct 104 ms 4988 KB Output is correct
9 Correct 97 ms 4988 KB Output is correct
10 Correct 89 ms 4988 KB Output is correct
11 Correct 100 ms 4988 KB Output is correct
12 Correct 95 ms 4988 KB Output is correct
13 Correct 127 ms 4988 KB Output is correct
14 Correct 97 ms 4988 KB Output is correct
15 Correct 86 ms 4988 KB Output is correct
16 Correct 102 ms 4988 KB Output is correct
17 Correct 108 ms 4988 KB Output is correct
18 Correct 125 ms 4988 KB Output is correct
19 Correct 111 ms 4988 KB Output is correct
20 Correct 122 ms 4988 KB Output is correct
21 Correct 83 ms 4988 KB Output is correct
22 Correct 99 ms 4988 KB Output is correct
23 Correct 94 ms 4988 KB Output is correct
24 Correct 69 ms 4988 KB Output is correct
25 Correct 121 ms 4988 KB Output is correct