# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
493815 | goodluck2020 | Brunhilda’s Birthday (BOI13_brunhilda) | C++14 | 507 ms | 157952 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
#define task "brunhilda"
using namespace std;
const int N = 1e5 + 5;
const int M = 2e7;
int m, q, A[N], Q[N];
namespace sub1
{
int dp[N];
void solve()
{
for(int i = 1; i <= 1e4; i++) dp[i] = 1e9;
for(int i = 1; i <= 1e4; i++)
for(int j = 1; j <= m; j++)
dp[i] = min(dp[i], dp[i - i % A[j]] + 1);
for(int i = 1; i <= q; i++)
{
if(dp[Q[i]] == 1e9) cout << "oo" << '\n';
else cout << dp[Q[i]] << '\n';
}
}
}
namespace sub2
{
int greed[M + 5], dp[M + 5];
long long lcm = 1;
void solve()
{
for(int i = 1; i <= m; i++)
lcm = min((long long)1e8,lcm * A[i]);
for(int i = 1; i <= m; i++)
for(int j = A[i] - 1; j <= M; j += A[i])
greed[j] = A[i] - 1;
for(int i = M; i >= 1; i--)
greed[i] = max(greed[i], greed[i + 1] - 1);
for(int i = 1; i <= M; i++)
dp[i] = dp[i - greed[i]] + 1;
for(int i = 1; i <= q; i++)
if(Q[i] >= lcm) cout << "oo" << '\n';
else cout << dp[Q[i]] << '\n';
}
}
int main()
{
if(fopen(task ".inp","r"))
{
freopen(task ".inp","r",stdin);
freopen(task ".out","w",stdout);
}
ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
cin >> m >> q;
int maxN = 0;
for(int i = 1; i <= m; i++) cin >> A[i];
for(int i = 1; i <= q; i++) cin >> Q[i], maxN = max(maxN, Q[i]);
if(m <= 1e4 && q <= 1e4 && maxN <= 1e4) sub1::solve();
else sub2::solve();
}
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... |