Submission #1211548

#TimeUsernameProblemLanguageResultExecution timeMemory
1211548Trn115생일수 I (GA4_birthday1)C++20
100 / 100
181 ms7160 KiB
#include <bits/stdc++.h>

#define fi first
#define se second
#define all(v) v.begin(), v.end()

using namespace std;

constexpr int inf = 1e7;

struct Answer
{
    int no3, no5, no8;

    Answer() = default;
    Answer(int x, int y, int z)
    {
        no3 = x;
        no5 = y;
        no8 = z;
    }

    bool operator<(const Answer &oth) const
    {
        int len = no3 + no5 + no8;
        int olen = oth.no3 + oth.no5 + oth.no8;
        return len < olen || (len == olen && no3 > 0);
    }
};

signed main()
{
    cin.tie(0)->sync_with_stdio(0);
    if (fopen("source.inp", "r"))
    {
        freopen("source.inp", "r", stdin);
        freopen("source.out", "w", stdout);
    }

    int t; cin >> t;
    while (t--)
    {
        int n; cin >> n;
        Answer res(inf, inf, inf);
        int no8 = 0;
        while (n >= 0)
        {
            if (n % 3 == 0)
            {
                res = min(res, Answer(n / 3, 0, no8));
            }
            if (n % 5 == 0)
            {
                res = min(res, Answer(0, n / 5, no8));
            }
            ++no8;
            n -= 8;
        }
        if (res.no3 == inf)
        {
            cout << -1 << "\n";
        }
        else
        {
            for (int i = 0; i < res.no3; ++i) cout << 3;
            for (int i = 0; i < res.no5; ++i) cout << 5;
            for (int i = 0; i < res.no8; ++i) cout << 8;
            cout << "\n";
        }
    }
}

Compilation message (stderr)

birthday1.cpp: In function 'int main()':
birthday1.cpp:36:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   36 |         freopen("source.inp", "r", stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~
birthday1.cpp:37:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   37 |         freopen("source.out", "w", stdout);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...