이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#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 time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |