# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
493815 | goodluck2020 | Brunhilda’s Birthday (BOI13_brunhilda) | C++14 | 507 ms | 157952 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#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();
}
컴파일 시 표준 에러 (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... |