# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1211548 | Trn115 | 생일수 I (GA4_birthday1) | C++20 | 181 ms | 7160 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)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |