답안 #20876

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
20876 2017-03-02T06:11:09 Z kdh9949 생일수 I (GA4_birthday1) C++14
14 / 100
109 ms 13652 KB
    #include <stdio.h>
    #include <queue>
    using namespace std;
     
    struct mindol{
        int three,five,eight;
        bool operator<(const mindol &a)const{
            int digit=three+five+eight;
            int adigit=a.three+a.five+a.eight;
            if(digit==adigit){
                if(three==a.three){
                    if(five==a.five){
                        return eight<a.eight;
                    }
                    return five<a.five;
                }
                return three<a.three;
            }
            return digit<adigit;
        }
    }ans[1000010];
     
    queue<mindol> q;
     
    void init(){
        for(int i=0;i<=1000000;i++)ans[i]={98769876,98769876,98769876};
        q.push({0,0,0});
        mindol cur;
        int sum;
        while(!q.empty()){
            cur=q.front();
            sum=cur.three*3+cur.five*5+cur.eight*8;
            q.pop();
            if(!(cur<ans[sum]))continue;
            ans[sum]=cur;
            q.push({cur.three+1,cur.five,cur.eight});
            q.push({cur.three,cur.five+1,cur.eight});
            q.push({cur.three,cur.five,cur.eight+1});
        }
    }
     
    int main()
    {
        init();
        int t,n;
        scanf("%d",&t);
        for(int i=0;i<t;i++){
            scanf("%d",&n);
            if(ans[n].three==98769876){puts("-1");continue;}
            for(int j=0;j<ans[n].three;j++)putchar('3');
            for(int j=0;j<ans[n].five;j++)putchar('5');
            for(int j=0;j<ans[n].eight;j++)putchar('8');
            putchar('\n');
        }
    }

Compilation message

birthday1.cpp: In function 'int main()':
birthday1.cpp:46:23: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf("%d",&t);
                       ^
birthday1.cpp:48:27: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
             scanf("%d",&n);
                           ^
# 결과 실행 시간 메모리 Grader output
1 Correct 49 ms 13652 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Incorrect 46 ms 13652 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 49 ms 13652 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 109 ms 13652 KB Output isn't correct
2 Halted 0 ms 0 KB -