Submission #575662

#TimeUsernameProblemLanguageResultExecution timeMemory
575662ktkeremBrunhilda’s Birthday (BOI13_brunhilda)C++17
97.78 / 100
354 ms88324 KiB
/*#pragma GCC target ("avx2")
#pragma GCC optimize ("O3")
#pragma GCC optimize("Ofast")
#pragma GCC optimize ("unroll-loops")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")*/
#include<bits/stdc++.h>
/*#include <bits/extc++.h>
using namespace std;
using namespace __gnu_pbds;
template<class T>
using oset = tree<T, null_type, less_equal<T>, rb_tree_tag, tree_order_statistics_node_update>;
/**/
//typedef int ll;
typedef long long ll;
typedef unsigned long long ull;
typedef __int128 vll;
typedef unsigned __int128 uvll;
ll _i=0;
#define ffn(x) _i=x
#define llll std::pair<ll , ll>
#define stitr set<ll>::iterator
#define fora(y,x) for(ll y=_i;x>y;y++)
#define pb push_back
#define pf push_front
#define halo cout << "hello\n"
#define fi first
#define sec second
#define all(a) a.begin() , a.end()
const ll limit = 1e9 + 7; 
const ll ous = 1e7 + 1e6 + 7;
const ll dx[4] = {1 , 0 , 0 , -1} , dy[4] = {0,1,-1,0};
void solve(){
    ll n , q;std::cin >> n >> q;
    ll dp[ous];memset(dp , 0 , sizeof(dp));
    fora(i , n){
        ll x;std::cin >> x;
        for(ll j = x-1;ous > j;j+=x){
            dp[j] = std::max(dp[j] , x-1);
        }
    }
    for(ll i = ous - 2;i>=0;i--){
        dp[i] = std::max(dp[i] , dp[i + 1] - 1);
    }
    for(ll i = 1;ous - 2 > i ; i++){
        if(dp[i] > 0){
            dp[i] = dp[i - dp[i]] + 1;
        }
        else{
            dp[i] = limit;
        }
    }
    fora(i , q){
        ll x;std::cin >> x;
        if(dp[x] == limit){
            std::cout << "oo" << "\n";
        }
        else{
            std::cout << dp[x] << "\n";
        }
    }
    return;/**/
}
signed main(){
    std::ios_base::sync_with_stdio(false);std::cin.tie(NULL);
    ll t=1;
    //std::cin >> t;
    ll o = 1;
    while(t--){ 
        //cout << "Case " << o++ << ":\n";
        solve();
    }
    return 0; 
}

Compilation message (stderr)

brunhilda.cpp:12:1: warning: "/*" within comment [-Wcomment]
   12 | /**/
      |  
brunhilda.cpp: In function 'int main()':
brunhilda.cpp:67:8: warning: unused variable 'o' [-Wunused-variable]
   67 |     ll o = 1;
      |        ^
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...