結果

問題 No.941 商とあまり
ユーザー pekempeypekempey
提出日時 2019-12-04 22:43:33
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 1,468 ms / 2,000 ms
コード長 4,495 bytes
コンパイル時間 2,990 ms
コンパイル使用メモリ 194,496 KB
実行使用メモリ 17,916 KB
最終ジャッジ日時 2023-08-21 04:47:58
合計ジャッジ時間 23,766 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 23 ms
7,804 KB
testcase_01 AC 8 ms
5,928 KB
testcase_02 AC 7 ms
5,744 KB
testcase_03 AC 388 ms
5,616 KB
testcase_04 AC 3 ms
5,628 KB
testcase_05 AC 3 ms
5,804 KB
testcase_06 AC 2 ms
5,640 KB
testcase_07 AC 796 ms
8,452 KB
testcase_08 AC 707 ms
8,416 KB
testcase_09 AC 566 ms
8,492 KB
testcase_10 AC 884 ms
8,416 KB
testcase_11 AC 77 ms
7,756 KB
testcase_12 AC 9 ms
7,656 KB
testcase_13 AC 3 ms
5,808 KB
testcase_14 AC 8 ms
7,752 KB
testcase_15 AC 307 ms
7,912 KB
testcase_16 AC 418 ms
8,248 KB
testcase_17 AC 3 ms
5,584 KB
testcase_18 AC 3 ms
5,696 KB
testcase_19 AC 3 ms
5,664 KB
testcase_20 AC 3 ms
5,628 KB
testcase_21 AC 2 ms
5,744 KB
testcase_22 AC 3 ms
5,684 KB
testcase_23 AC 2 ms
5,492 KB
testcase_24 AC 2 ms
5,424 KB
testcase_25 AC 2 ms
5,484 KB
testcase_26 AC 214 ms
7,696 KB
testcase_27 AC 1,122 ms
9,896 KB
testcase_28 AC 8 ms
7,716 KB
testcase_29 AC 238 ms
8,136 KB
testcase_30 AC 238 ms
8,348 KB
testcase_31 AC 8 ms
7,692 KB
testcase_32 AC 505 ms
8,436 KB
testcase_33 AC 3 ms
5,600 KB
testcase_34 AC 2 ms
5,612 KB
testcase_35 AC 2 ms
5,600 KB
testcase_36 AC 9 ms
7,956 KB
testcase_37 AC 1,113 ms
9,112 KB
testcase_38 AC 1,110 ms
9,296 KB
testcase_39 AC 2 ms
5,604 KB
testcase_40 AC 3 ms
5,588 KB
testcase_41 AC 3 ms
5,588 KB
testcase_42 AC 2 ms
5,708 KB
testcase_43 AC 5 ms
7,740 KB
testcase_44 AC 779 ms
8,412 KB
testcase_45 AC 239 ms
8,668 KB
testcase_46 AC 125 ms
7,908 KB
testcase_47 AC 6 ms
7,676 KB
testcase_48 AC 3 ms
5,680 KB
testcase_49 AC 970 ms
9,844 KB
testcase_50 AC 541 ms
9,028 KB
testcase_51 AC 516 ms
9,668 KB
testcase_52 AC 540 ms
8,772 KB
testcase_53 AC 515 ms
8,964 KB
testcase_54 AC 298 ms
9,016 KB
testcase_55 AC 366 ms
9,020 KB
testcase_56 AC 1,468 ms
17,916 KB
testcase_57 AC 3 ms
5,808 KB
testcase_58 AC 3 ms
5,680 KB
testcase_59 AC 9 ms
7,660 KB
testcase_60 AC 8 ms
7,752 KB
testcase_61 AC 8 ms
7,760 KB
testcase_62 AC 3 ms
5,600 KB
testcase_63 AC 3 ms
5,704 KB
testcase_64 AC 3 ms
5,600 KB
testcase_65 AC 3 ms
5,596 KB
testcase_66 AC 10 ms
7,632 KB
testcase_67 AC 3 ms
5,640 KB
testcase_68 AC 10 ms
7,788 KB
testcase_69 AC 3 ms
5,628 KB
testcase_70 AC 3 ms
5,648 KB
testcase_71 AC 11 ms
7,732 KB
testcase_72 AC 11 ms
7,640 KB
testcase_73 AC 3 ms
5,708 KB
testcase_74 AC 3 ms
5,752 KB
testcase_75 AC 3 ms
5,716 KB
testcase_76 AC 3 ms
5,912 KB
testcase_77 AC 3 ms
5,664 KB
testcase_78 AC 3 ms
5,584 KB
testcase_79 AC 3 ms
5,752 KB
testcase_80 AC 3 ms
5,584 KB
testcase_81 AC 3 ms
5,916 KB
testcase_82 AC 3 ms
5,608 KB
testcase_83 AC 3 ms
5,744 KB
testcase_84 AC 3 ms
5,584 KB
testcase_85 AC 3 ms
5,628 KB
testcase_86 AC 3 ms
5,704 KB
testcase_87 AC 3 ms
5,624 KB
testcase_88 AC 3 ms
5,696 KB
testcase_89 AC 3 ms
5,668 KB
testcase_90 AC 3 ms
5,668 KB
testcase_91 AC 3 ms
5,668 KB
testcase_92 AC 3 ms
5,668 KB
testcase_93 AC 3 ms
5,716 KB
testcase_94 AC 3 ms
5,744 KB
testcase_95 AC 3 ms
5,756 KB
testcase_96 AC 3 ms
5,588 KB
testcase_97 AC 3 ms
5,776 KB
testcase_98 AC 3 ms
5,912 KB
testcase_99 AC 2 ms
5,756 KB
testcase_100 AC 2 ms
5,908 KB
testcase_101 AC 3 ms
5,712 KB
testcase_102 AC 2 ms
5,708 KB
testcase_103 AC 3 ms
5,752 KB
testcase_104 AC 2 ms
5,404 KB
testcase_105 AC 2 ms
7,440 KB
testcase_106 AC 2 ms
5,416 KB
testcase_107 AC 2 ms
5,404 KB
testcase_108 AC 2 ms
7,456 KB
testcase_109 AC 2 ms
7,492 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#pragma GCC optimize ("O3")
#pragma GCC target ("avx")
#include <bits/stdc++.h>

using namespace std;
using ll = long long;
 
#define rep(i, n)      for (int i = 0; i < (n); i++)
#define repr(i, n)     for (int i = (n) - 1; i >= 0; i--)
#define repe(i, l, r)  for (int i = (l); i < (r); i++)
#define reper(i, l, r) for (int i = (r) - 1; i >= (l); i--)
#define repi(i, l, r)  for (int i = (l); i <= (r); i++)
#define repir(i, l, r) for (int i = (r); i >= (l); i--)
#define range(a) a.begin(), a.end()
void initio() { cin.tie(nullptr); ios::sync_with_stdio(false); cout << fixed << setprecision(15); }

bool can[500001];

set< vector<ll> > st;

bitset<500001> dp[1 << 11];
bitset<500001> checked[1 << 11];
int N;
ll A[500010];
ll prod[1 << 11];
int root[1 << 11];
int cnt;
ll X;

clock_t beg;

void solve2() {
  vector<bitset<500001>> bs(N);
  rep(i, N) {
    for (int j = 0; j <= X; j += A[i]) bs[i][j] = true;
  }
  int U = (1 << N) - 1;
  repe(i, 1, 1 << N) {
    if (root[i] != i) continue;
    if ((i & i - 1) == 0) {
      dp[i][prod[i] - 1] = true;
      continue;
    }
    rep(j, N) if (i >> j & 1) {
      if (root[i ^ 1 << j] != (i ^ 1 << j)) continue;
      for (ll k = prod[i ^ 1 << j] - 1; (k + 1) * prod[U ^ i ^ (1 << j)] - 1 <= X && k < prod[i ^ 1 << j] - 1 + 20*A[j]; k++) if (dp[i ^ 1 << j][k]) {
        dp[i] |= bs[j] << ((k + 1) * (A[j] + 1) - 1);
        // for (ll l = (k + 1) * (A[j] + 1) - 1; (l + 1) * prod[U ^ i] - 1 <= X; l += A[j]) {
        //    dp[i][l] = true;
        // }
      }
    }
  }
  string ans(X, '0');
  for (int i = 1; i <= X; i++) {
    ans[i - 1] = dp[U][i] ? '1' : '0';
  }
  cerr << count(range(ans), '1') << endl;
  cout << ans << endl;
}

void solve() {
  vector<bitset<500001>> bs(N);
  rep(i, N) {
    for (int j = 0; j <= X; j += A[i]) bs[i][j] = true;
  }
  int U = (1 << N) - 1;
  repe(i, 1, 1 << N) {
    if (root[i] != i) continue;
    if ((i & i - 1) == 0) {
      dp[i][prod[i] - 1] = true;
      continue;
    }
   
    rep(j, N) if (i >> j & 1) {
      if (root[i ^ 1 << j] != (i ^ 1 << j)) continue;
      for (ll k = prod[i ^ 1 << j] - 1; (k + 1) * prod[U ^ i ^ (1 << j)] - 1 <= X; k++) if (dp[i ^ 1 << j][k]) {
         if ((double)(clock() - beg) / CLOCKS_PER_SEC >= 1.1) {
          solve2();
          exit(0);
        }
        dp[i] |= bs[j] << ((k + 1) * (A[j] + 1) - 1);
        // for (ll l = (k + 1) * (A[j] + 1) - 1; (l + 1) * prod[U ^ i] - 1 <= X; l += A[j]) {
        //    dp[i][l] = true;
        // }
      }
    }
  }
  string ans(X, '0');
  for (int i = 1; i <= X; i++) {
    ans[i - 1] = dp[U][i] ? '1' : '0';
  }
  cerr << count(range(ans), '1') << endl;
  cout << ans << endl;
}

bool dfs(int x, int u) {
  if ((double)(clock() - beg) / CLOCKS_PER_SEC >= 0.5) {
    solve();
    exit(0);
  }
  u = root[u];
  if (checked[u][x]) return dp[u][x];
  cnt++;
  checked[u][x] = true;
  if (prod[u] - 1 > x) return dp[u][x] = false;
  if ((u & u - 1) == 0) return dp[u][x] = prod[u] - 1 == x;
  rep(i, N) if (u >> i & 1) {
    if ((x - (prod[u] - 1)) % A[i] == 0) return dp[u][x] = true;
  }
  for (int i = (u - 1) & u; i != 0; i = (i - 1) & u) {
    if (root[i] != i) continue;
    int j = u ^ i;
    for (int k = prod[j]; k <= x && prod[i] - 1 <= x / k; k++) if (x % k != 0) {
      if (dfs(x % k, j) && dfs(x / k, i)) {
        return dp[u][x] = true;
      }
    }
  }
  return dp[u][x] = false;
}



int main() {
  beg = clock();
  cin >> N >> X;
  rep(i, N) cin >> A[i];
  sort(A, A + N);
  ll p = 1;
  rep(i, N) {
    p *= A[i] + 1;
    if (p - 1 > X) {
      cout << string(X, '0') << endl;
      return 0;
    }
  }
  ll g = 0;
  rep(i, N) g = __gcd(g, A[i]);
  if (count(A, A + N, 1) > 0 && N >= 2) {
    string ans(X, '0');
    for (int i = p - 1; i <= X; i++) {
      ans[i - 1] = '1';
    }
    cout << ans << endl;
    return 0;
  }
  rep(i, 1 << N) prod[i] = 1;
  rep(i, 1 << N) rep(j, N) if (i >> j & 1) {
    prod[i] *= A[j] + 1;
  }
  rep(i, 1 << N) {
    vector<ll> a;
    rep(j, N) if (i >> j & 1) a.push_back(A[j]);
    int mask = 0;
    int k = 0;
    rep(j, N) {
      if (k < a.size() && a[k] == A[j]) {
        mask |= 1 << j;
        k++;
      }
    }
    root[i] = mask;
  }
  cerr << "here" << endl;
  string ans(X, '0');
  int cont = 0;
  for (int i = p - 1; i <= X; i++) {
    if ((i - (p - 1)) % g != 0) continue;
    if (cont >= 100 || dfs(i, (1 << N) - 1)) {
      ans[i - 1] = '1';
      cont++;
    } else {
      cont = 0;
    }
  }
  cout << ans << endl;
  cerr << cnt << endl;
}
0