# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
26998 | noobprogrammer | Brunhilda’s Birthday (BOI13_brunhilda) | C++14 | 219 ms | 119596 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
using namespace std ;
int n , m , pr[100010] , mx[10000010] , ft[10000010] , ptr , dp[10000010] ;
const int N = 1e7 ;
// 1e7 - x + 1 ;
void upd(int x , int val){
for( ;x<=N ;x+= (x&(-x))) ft[x] = min(ft[x] , val) ;
}
int qr(int x){
int res = 1e9 ;
for(;x>0;x-=(x&(-x)) ) res = min(ft[x] , res) ;
return res ;
}
int main(){
freopen("in.txt" , "r" , stdin) ;
// freopen("out.txt" , "w" , stdout) ;
scanf("%d%d" , &n,&m ) ;
for(int i = 1 ;i<=N;i++) ft[i] = 1e9 ;
for(int i=0;i<n;i++) {
scanf("%d" , pr+i) ;
for(int j=0 ; j <= (int)1e7 ; j+=pr[i]) mx[j] = max(mx[j] , pr[i]) ;
}
upd( 1e7 - mx[0] + 2 , 1 ) ;
int val ;
for(int i=1;i<=N;i++){
ptr = N-i+1 ;
dp[i] = qr(ptr) ;
// printf("%d %d %d\n" , i , dp[i] , ptr) ;
ptr = N - (i + mx[i] - 1 ) + 1 ;
if(dp[i] == 1e9) continue ;
if(ptr > N) continue ;
upd(ptr , dp[i] + 1) ;
}
for(int i=0;i<m;i++){
scanf("%d" , &val) ;
if(dp[val] == 1e9) printf("oo\n") ;
else printf("%d\n" , dp[val] ) ;
}
}
Compilation message (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... |