Submission #399273

#TimeUsernameProblemLanguageResultExecution timeMemory
399273cpp219Brunhilda’s Birthday (BOI13_brunhilda)C++14
100 / 100
480 ms188776 KiB
#pragma GCC optimization "O2"
#pragma GCC optimization "unroll-loop"
#pragma GCC target ("avx2")

#include<bits/stdc++.h>
#define ll long long
#define ld long double
#define fs first
#define sc second
using namespace std;
typedef pair<ll,ll> LL;
const ll N = 12e6 + 9;
const ll inf = 1e9 + 7;

ll n,Q,dp[N],jump[N],x;

int main(){
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    #define task "tst"
    if (fopen(task".inp","r")){
        freopen(task".inp","r",stdin);
        //freopen(task".out","w",stdout);
    }
    cin>>n>>Q;
    for (ll i = 1;i <= n;i++){
        cin>>x;
        for (ll j = x - 1;j < N;j += x) jump[j] = x - 1;
    }
    for (ll i = N - 3;i >= 1;i--){
        dp[i] = inf;
        jump[i] = max(jump[i],jump[i + 1] - 1);
    }
    dp[0] = 0;
    for (ll i = 1;i < N;i++){
        ll nxt = max(0ll,i - jump[i]);
        dp[i] = min(dp[i],dp[nxt] + 1);
    }
    while(Q--){
        cin>>x;
        if (dp[x] == inf) cout<<"oo";
        else cout<<dp[x]; cout<<"\n";
    }
}

Compilation message (stderr)

brunhilda.cpp:1: warning: ignoring #pragma GCC optimization [-Wunknown-pragmas]
    1 | #pragma GCC optimization "O2"
      | 
brunhilda.cpp:2: warning: ignoring #pragma GCC optimization [-Wunknown-pragmas]
    2 | #pragma GCC optimization "unroll-loop"
      | 
brunhilda.cpp: In function 'int main()':
brunhilda.cpp:41:9: warning: this 'else' clause does not guard... [-Wmisleading-indentation]
   41 |         else cout<<dp[x]; cout<<"\n";
      |         ^~~~
brunhilda.cpp:41:27: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'else'
   41 |         else cout<<dp[x]; cout<<"\n";
      |                           ^~~~
brunhilda.cpp:21:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)', declared with attribute warn_unused_result [-Wunused-result]
   21 |         freopen(task".inp","r",stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...