답안 #310467

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
310467 2020-10-07T04:39:24 Z caoash Brunhilda’s Birthday (BOI13_brunhilda) C++14
100 / 100
663 ms 157744 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 int INF = (int) 987654321;

#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

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

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

# 결과 실행 시간 메모리 Grader output
1 Correct 219 ms 156920 KB Output is correct
2 Correct 296 ms 156920 KB Output is correct
3 Correct 263 ms 157048 KB Output is correct
4 Correct 214 ms 156920 KB Output is correct
5 Correct 242 ms 156920 KB Output is correct
6 Correct 219 ms 156920 KB Output is correct
7 Correct 261 ms 156920 KB Output is correct
8 Correct 285 ms 156924 KB Output is correct
9 Correct 323 ms 156920 KB Output is correct
10 Correct 354 ms 156880 KB Output is correct
11 Correct 326 ms 156920 KB Output is correct
12 Correct 212 ms 156920 KB Output is correct
13 Correct 520 ms 156888 KB Output is correct
14 Correct 522 ms 156920 KB Output is correct
15 Correct 312 ms 156920 KB Output is correct
16 Correct 298 ms 156920 KB Output is correct
17 Correct 261 ms 156920 KB Output is correct
18 Correct 216 ms 156876 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 249 ms 156996 KB Output is correct
2 Correct 264 ms 157556 KB Output is correct
3 Correct 612 ms 157344 KB Output is correct
4 Correct 286 ms 156920 KB Output is correct
5 Correct 440 ms 157248 KB Output is correct
6 Correct 276 ms 156920 KB Output is correct
7 Correct 242 ms 156996 KB Output is correct
8 Correct 281 ms 156920 KB Output is correct
9 Correct 498 ms 157428 KB Output is correct
10 Correct 616 ms 157296 KB Output is correct
11 Correct 610 ms 157180 KB Output is correct
12 Correct 369 ms 156920 KB Output is correct
13 Correct 232 ms 156920 KB Output is correct
14 Correct 285 ms 156920 KB Output is correct
15 Correct 499 ms 157304 KB Output is correct
16 Correct 262 ms 157428 KB Output is correct
17 Correct 532 ms 156920 KB Output is correct
18 Correct 490 ms 157556 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 506 ms 157436 KB Output is correct
2 Correct 633 ms 157304 KB Output is correct
3 Correct 629 ms 157432 KB Output is correct
4 Correct 402 ms 157176 KB Output is correct
5 Correct 300 ms 157552 KB Output is correct
6 Correct 522 ms 157304 KB Output is correct
7 Correct 440 ms 157540 KB Output is correct
8 Correct 526 ms 157560 KB Output is correct
9 Correct 525 ms 157432 KB Output is correct
10 Correct 406 ms 156920 KB Output is correct
11 Correct 365 ms 157048 KB Output is correct
12 Correct 482 ms 157180 KB Output is correct
13 Correct 585 ms 157432 KB Output is correct
14 Correct 400 ms 157560 KB Output is correct
15 Correct 522 ms 157176 KB Output is correct
16 Correct 567 ms 157176 KB Output is correct
17 Correct 486 ms 157196 KB Output is correct
18 Correct 624 ms 157304 KB Output is correct
19 Correct 259 ms 156940 KB Output is correct
20 Correct 629 ms 157560 KB Output is correct
21 Correct 437 ms 157520 KB Output is correct
22 Correct 647 ms 157744 KB Output is correct
23 Correct 304 ms 157428 KB Output is correct
24 Correct 264 ms 157176 KB Output is correct
25 Correct 436 ms 157304 KB Output is correct
26 Correct 406 ms 157176 KB Output is correct
27 Correct 663 ms 157684 KB Output is correct
28 Correct 278 ms 157176 KB Output is correct
29 Correct 564 ms 157672 KB Output is correct
30 Correct 521 ms 157556 KB Output is correct
31 Correct 306 ms 157176 KB Output is correct
32 Correct 332 ms 157176 KB Output is correct
33 Correct 242 ms 157304 KB Output is correct
34 Correct 443 ms 157556 KB Output is correct
35 Correct 287 ms 157304 KB Output is correct
36 Correct 602 ms 157684 KB Output is correct
37 Correct 305 ms 157556 KB Output is correct
38 Correct 517 ms 157200 KB Output is correct
39 Correct 283 ms 157432 KB Output is correct
40 Correct 454 ms 157304 KB Output is correct
41 Correct 413 ms 157580 KB Output is correct
42 Correct 586 ms 157304 KB Output is correct