Submission #2152

# Submission time Handle Problem Language Result Execution time Memory
2152 2013-07-20T05:46:04 Z mhkim4886 생일수 I (GA4_birthday1) C++
33 / 100
1 ms 8700 KB
#include <stdio.h>

typedef struct _Num
{
    long long num;
    int total;
} Num;

long long out[101], n, qrear = 1, qtail = 1;
Num que[500001];

int main()
{
    scanf("%d", &n);

    for(int i = 1; i <= n; i++)
    {
        int k;
        scanf("%d", &k);

        qrear = 1;
        qtail = 4;
        que[1].num = que[1].total = 3;
        que[2].num = que[2].total = 5;
        que[3].num = que[3].total = 8;

        while(true)
        {
            int q = que[qrear++].total;
            if(q == k)
            {
                out[i] = que[qrear-1].num;
                break;
            }
            else
            {
                long long p = que[qrear-1].num % 10;

                if(que[qrear-1].total + 3 <= k && p <= 3)
                {
                    que[qtail].num = que[qrear-1].num * 10 + 3;
                    que[qtail++].total = que[qrear-1].total + 3;
                }
                if(que[qrear-1].total + 5 <= k && p <= 5)
                {
                    que[qtail].num = que[qrear-1].num * 10 + 5;
                    que[qtail++].total = que[qrear-1].total + 5;
                }
                if(que[qrear-1].total + 8 <= k && p <= 8)
                {
                    que[qtail].num = que[qrear-1].num * 10 + 8;
                    que[qtail++].total = que[qrear-1].total + 8;
                }
            }

            if(qrear == qtail)
            {
                out[i] = -1;
                break;
            }
        }
    }

    for(int i = 1; i <= n; i++) printf("%lld\n", out[i]);
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 8700 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 8700 KB Output is correct
# Verdict Execution time Memory Grader output
1 Runtime error 0 ms 8696 KB SIGSEGV Segmentation fault
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 1 ms 8696 KB SIGSEGV Segmentation fault
2 Halted 0 ms 0 KB -