제출 #447674

#제출 시각아이디문제언어결과실행 시간메모리
447674NguyenDNBrunhilda’s Birthday (BOI13_brunhilda)C++14
100 / 100
477 ms189940 KiB
#include <bits/stdc++.h>
/*
#pragma comment(linker, "/stack:200000000")
#pragma GCC target("avx,avx2,fma")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#pragma GCC optimization ("O3")
#pragma GCC optimization ("unroll-loops")
*/
#define pb push_back
#define gcin(s) getline(cin,s)
#define el "\n"
#define sz(s) s.size()
#define fi first
#define sc second
#define testbit(n, bit) ((n>>bit) & 1)
#define flipbit(n, bit) (n ^ (1ll << bit))
#define reset(x, num) memset(x, num, sizeof(x))
#define all(x) x.begin(), x.end()
#define task "BIRTHDAY"
#define ll long long
#define ull unsigned long long
#define ld long double
using namespace std;
const ll maxe=12e6+10;
const ll maxf=1e3+1;
const ll oo=1e18;
const ll mod=1e9+7;
const ld Pi=atan(1.0L) * 4;
typedef ll mang[maxe];
typedef ll bang[maxf][maxf];
ll n, q;
mang jump, f;
int main () {
    ios_base:: sync_with_stdio(false);
    cout.tie(nullptr); cin.tie(nullptr);
    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++){
        ll x;
        cin >> x;
        for (ll j=x-1; j<maxe; j+=x) jump[j]=x-1;
    }
    for (ll i=maxe-3; i>=1; i--){
        f[i]=oo;
        jump[i]=max(jump[i],jump[i+1] - 1);
    }
    f[0]=0;
    for (ll i=1; i<maxe; i++){
        ll nxt=max(0ll, i-jump[i]);
        f[i]=min(f[i], f[nxt] + 1);
    }
    while(q--){
        ll x;
        cin >> x;
        if (f[x]==oo) cout << "oo" << el;
        else cout << f[x] << el;
    }
}

////////////////////////////////////////////////////////////////////////////////////////
//                                                                                    //
//                          Coded by Nguyen Duc Nam                                   //
//                                                                                    //
////////////////////////////////////////////////////////////////////////////////////////

컴파일 시 표준 에러 (stderr) 메시지

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