답안 #310465

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
310465 2020-10-07T04:26:54 Z caoash Brunhilda’s Birthday (BOI13_brunhilda) C++14
0 / 100
986 ms 262148 KB
#include <bits/stdc++.h> 
using namespace std;

using ll = long long;

using vi = vector<int>;
using vl = vector<ll>;
#define pb push_back
#define rsz resize
#define all(x) begin(x), end(x)
#define sz(x) (int)(x).size()

using pi = pair<int,int>;
#define f first
#define s second
#define mp make_pair

const ll MX = 20000005;
const int MOD = (int) (1e9 + 7);
const ll INF = (ll) 1e18;

#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;

namespace output {
  void pr(int x) {
    cout << x;
  }
  void pr(long x) {
    cout << x;
  }
  void pr(ll x) {
    cout << x;
  }
  void pr(unsigned x) {
    cout << x;
  }
  void pr(unsigned long x) {
    cout << x;
  }
  void pr(unsigned long long x) {
    cout << x;
  }
  void pr(float x) {
    cout << x;
  }
  void pr(double x) {
    cout << x;
  }
  void pr(long double x) {
    cout << x;
  }
  void pr(char x) {
    cout << x;
  }
  void pr(const char * x) {
    cout << x;
  }
  void pr(const string & x) {
    cout << x;
  }
  void pr(bool x) {
    pr(x ? "true" : "false");
  }

  template < class T1, class T2 > void pr(const pair < T1, T2 > & x);
  template < class T > void pr(const T & x);

  template < class T, class...Ts > void pr(const T & t,
    const Ts & ...ts) {
    pr(t);
    pr(ts...);
  }
  template < class T1, class T2 > void pr(const pair < T1, T2 > & x) {
    pr("{", x.f, ", ", x.s, "}");
  }
  template < class T > void pr(const T & x) {
    pr("{"); // const iterator needed for vector<bool>
    bool fst = 1;
    for (const auto & a: x) pr(!fst ? ", " : "", a), fst = 0;
    pr("}");
  }

  void ps() {
    pr("\n");
  } // print w/ spaces
  template < class T, class...Ts > void ps(const T & t,
    const Ts & ...ts) {
    pr(t);
    if (sizeof...(ts)) pr(" ");
    ps(ts...);
  }

  void pc() {
    cout << "]" << endl;
  } // debug w/ commas
  template < class T, class...Ts > void pc(const T & t,
    const Ts & ...ts) {
    pr(t);
    if (sizeof...(ts)) pr(", ");
    pc(ts...);
  }
  #define dbg(x...) pr("[", #x, "] = ["), pc(x);
}

#ifdef LOCAL
using namespace output;
#endif

ll dp[MX];
ll trans[MX];
bool has[MX];
int n, m; 
vector<ll> prim;

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cin >> n >> m;
    for (int i = 0; i < n; i++) {
        ll x; cin >> x;
        prim.pb(x);
    }
    for (int i = 0; i < n; i++) {
        for (ll j = prim[i] - 1; j <= MX; j += prim[i]) {
            if (prim[i] - 1 > trans[j]) has[j] = true;
            trans[j] = max(trans[j], prim[i] - 1);
        }
    }
    for (int i = 1; i < MX; i++) {
        if (has[i - 1]) {
            trans[i] = max(trans[i], 0LL);
        } else {
            trans[i] = max(trans[i], trans[i - 1]);
        }
    }
    for (int i = 0; i < MX; i++) dp[i] = INF;
    dp[0] = 0;
    for (ll i = 1; i < MX; i++) {
        ll best = i - trans[i];
        if (best == INF) {
            dp[i] = INF;
        } else {
            dp[i] = min(INF, dp[best] + 1);
        }
    }
    for (int i = 0; i < m; i++) {
        ll v; cin >> v;
        ll ans = dp[v];
        if (ans == INF) cout << "oo" << '\n';
        else cout << ans << '\n';
    }
}

# 결과 실행 시간 메모리 Grader output
1 Runtime error 231 ms 262148 KB Execution killed with signal 9 (could be triggered by violating memory limits)
2 Runtime error 335 ms 262148 KB Execution killed with signal 9 (could be triggered by violating memory limits)
3 Runtime error 276 ms 262148 KB Execution killed with signal 9 (could be triggered by violating memory limits)
4 Runtime error 246 ms 262144 KB Execution killed with signal 9 (could be triggered by violating memory limits)
5 Runtime error 299 ms 262148 KB Execution killed with signal 9 (could be triggered by violating memory limits)
6 Runtime error 235 ms 262148 KB Execution killed with signal 9 (could be triggered by violating memory limits)
7 Runtime error 277 ms 262148 KB Execution killed with signal 9 (could be triggered by violating memory limits)
8 Runtime error 302 ms 262148 KB Execution killed with signal 9 (could be triggered by violating memory limits)
9 Runtime error 360 ms 262148 KB Execution killed with signal 9 (could be triggered by violating memory limits)
10 Runtime error 438 ms 262148 KB Execution killed with signal 9 (could be triggered by violating memory limits)
11 Runtime error 428 ms 262148 KB Execution killed with signal 9 (could be triggered by violating memory limits)
12 Runtime error 246 ms 262148 KB Execution killed with signal 9 (could be triggered by violating memory limits)
13 Runtime error 742 ms 262148 KB Execution killed with signal 9 (could be triggered by violating memory limits)
14 Runtime error 737 ms 262144 KB Execution killed with signal 9 (could be triggered by violating memory limits)
15 Runtime error 369 ms 262148 KB Execution killed with signal 9 (could be triggered by violating memory limits)
16 Runtime error 330 ms 262144 KB Execution killed with signal 9 (could be triggered by violating memory limits)
17 Runtime error 352 ms 262148 KB Execution killed with signal 9 (could be triggered by violating memory limits)
18 Runtime error 252 ms 262148 KB Execution killed with signal 9 (could be triggered by violating memory limits)
# 결과 실행 시간 메모리 Grader output
1 Runtime error 304 ms 262148 KB Execution killed with signal 9 (could be triggered by violating memory limits)
2 Runtime error 341 ms 262148 KB Execution killed with signal 9 (could be triggered by violating memory limits)
3 Runtime error 915 ms 262148 KB Execution killed with signal 9 (could be triggered by violating memory limits)
4 Runtime error 423 ms 262148 KB Execution killed with signal 9 (could be triggered by violating memory limits)
5 Runtime error 637 ms 262148 KB Execution killed with signal 9 (could be triggered by violating memory limits)
6 Runtime error 325 ms 262148 KB Execution killed with signal 9 (could be triggered by violating memory limits)
7 Runtime error 317 ms 262148 KB Execution killed with signal 9 (could be triggered by violating memory limits)
8 Runtime error 407 ms 262148 KB Execution killed with signal 9 (could be triggered by violating memory limits)
9 Runtime error 731 ms 262148 KB Execution killed with signal 9 (could be triggered by violating memory limits)
10 Runtime error 915 ms 262148 KB Execution killed with signal 9 (could be triggered by violating memory limits)
11 Runtime error 901 ms 262148 KB Execution killed with signal 9 (could be triggered by violating memory limits)
12 Runtime error 530 ms 262148 KB Execution killed with signal 9 (could be triggered by violating memory limits)
13 Runtime error 264 ms 262148 KB Execution killed with signal 9 (could be triggered by violating memory limits)
14 Runtime error 434 ms 262148 KB Execution killed with signal 9 (could be triggered by violating memory limits)
15 Runtime error 742 ms 262148 KB Execution killed with signal 9 (could be triggered by violating memory limits)
16 Runtime error 351 ms 262148 KB Execution killed with signal 9 (could be triggered by violating memory limits)
17 Runtime error 778 ms 262148 KB Execution killed with signal 9 (could be triggered by violating memory limits)
18 Runtime error 736 ms 262148 KB Execution killed with signal 9 (could be triggered by violating memory limits)
# 결과 실행 시간 메모리 Grader output
1 Runtime error 739 ms 262148 KB Execution killed with signal 9 (could be triggered by violating memory limits)
2 Runtime error 932 ms 262148 KB Execution killed with signal 9 (could be triggered by violating memory limits)
3 Runtime error 933 ms 262148 KB Execution killed with signal 9 (could be triggered by violating memory limits)
4 Runtime error 530 ms 262144 KB Execution killed with signal 9 (could be triggered by violating memory limits)
5 Runtime error 368 ms 262148 KB Execution killed with signal 9 (could be triggered by violating memory limits)
6 Runtime error 718 ms 262148 KB Execution killed with signal 9 (could be triggered by violating memory limits)
7 Runtime error 666 ms 262148 KB Execution killed with signal 9 (could be triggered by violating memory limits)
8 Runtime error 718 ms 262148 KB Execution killed with signal 9 (could be triggered by violating memory limits)
9 Runtime error 729 ms 262148 KB Execution killed with signal 9 (could be triggered by violating memory limits)
10 Runtime error 633 ms 262144 KB Execution killed with signal 9 (could be triggered by violating memory limits)
11 Runtime error 546 ms 262148 KB Execution killed with signal 9 (could be triggered by violating memory limits)
12 Runtime error 680 ms 262144 KB Execution killed with signal 9 (could be triggered by violating memory limits)
13 Runtime error 855 ms 262144 KB Execution killed with signal 9 (could be triggered by violating memory limits)
14 Runtime error 467 ms 262148 KB Execution killed with signal 9 (could be triggered by violating memory limits)
15 Runtime error 718 ms 262148 KB Execution killed with signal 9 (could be triggered by violating memory limits)
16 Runtime error 818 ms 262148 KB Execution killed with signal 9 (could be triggered by violating memory limits)
17 Runtime error 722 ms 262148 KB Execution killed with signal 9 (could be triggered by violating memory limits)
18 Runtime error 913 ms 262148 KB Execution killed with signal 9 (could be triggered by violating memory limits)
19 Runtime error 287 ms 262148 KB Execution killed with signal 9 (could be triggered by violating memory limits)
20 Runtime error 924 ms 262148 KB Execution killed with signal 9 (could be triggered by violating memory limits)
21 Runtime error 553 ms 262148 KB Execution killed with signal 9 (could be triggered by violating memory limits)
22 Runtime error 889 ms 262148 KB Execution killed with signal 9 (could be triggered by violating memory limits)
23 Runtime error 390 ms 262148 KB Execution killed with signal 9 (could be triggered by violating memory limits)
24 Runtime error 287 ms 262148 KB Execution killed with signal 9 (could be triggered by violating memory limits)
25 Runtime error 600 ms 262148 KB Execution killed with signal 9 (could be triggered by violating memory limits)
26 Runtime error 527 ms 262148 KB Execution killed with signal 9 (could be triggered by violating memory limits)
27 Runtime error 986 ms 262148 KB Execution killed with signal 9 (could be triggered by violating memory limits)
28 Runtime error 308 ms 262148 KB Execution killed with signal 9 (could be triggered by violating memory limits)
29 Runtime error 844 ms 262148 KB Execution killed with signal 9 (could be triggered by violating memory limits)
30 Runtime error 771 ms 262148 KB Execution killed with signal 9 (could be triggered by violating memory limits)
31 Runtime error 379 ms 262148 KB Execution killed with signal 9 (could be triggered by violating memory limits)
32 Runtime error 442 ms 262148 KB Execution killed with signal 9 (could be triggered by violating memory limits)
33 Runtime error 245 ms 262148 KB Execution killed with signal 9 (could be triggered by violating memory limits)
34 Runtime error 669 ms 262148 KB Execution killed with signal 9 (could be triggered by violating memory limits)
35 Runtime error 352 ms 262148 KB Execution killed with signal 9 (could be triggered by violating memory limits)
36 Runtime error 866 ms 262148 KB Execution killed with signal 9 (could be triggered by violating memory limits)
37 Runtime error 366 ms 262148 KB Execution killed with signal 9 (could be triggered by violating memory limits)
38 Runtime error 722 ms 262144 KB Execution killed with signal 9 (could be triggered by violating memory limits)
39 Runtime error 329 ms 262148 KB Execution killed with signal 9 (could be triggered by violating memory limits)
40 Runtime error 627 ms 262148 KB Execution killed with signal 9 (could be triggered by violating memory limits)
41 Runtime error 575 ms 262148 KB Execution killed with signal 9 (could be triggered by violating memory limits)
42 Runtime error 816 ms 262148 KB Execution killed with signal 9 (could be triggered by violating memory limits)