제출 #493814

#제출 시각아이디문제언어결과실행 시간메모리
493814goodluck2020Brunhilda’s Birthday (BOI13_brunhilda)C++14
77.46 / 100
237 ms81060 KiB
#include <bits/stdc++.h>
#define task "brunhilda"

using namespace std;
const int N = 1e5 + 5;
const int M = 1e7;
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) 메시지

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