結果

問題 No.941 商とあまり
ユーザー pekempeypekempey
提出日時 2019-12-04 22:25:45
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
TLE  
実行時間 -
コード長 3,340 bytes
コンパイル時間 1,818 ms
コンパイル使用メモリ 178,692 KB
実行使用メモリ 8,608 KB
最終ジャッジ日時 2023-08-21 04:16:05
合計ジャッジ時間 14,815 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 22 ms
7,652 KB
testcase_01 AC 8 ms
5,708 KB
testcase_02 AC 7 ms
5,780 KB
testcase_03 AC 387 ms
5,672 KB
testcase_04 AC 2 ms
5,776 KB
testcase_05 AC 3 ms
5,668 KB
testcase_06 AC 2 ms
5,668 KB
testcase_07 AC 1,413 ms
8,444 KB
testcase_08 AC 1,288 ms
8,500 KB
testcase_09 AC 1,091 ms
8,608 KB
testcase_10 AC 1,533 ms
8,436 KB
testcase_11 AC 77 ms
7,668 KB
testcase_12 AC 8 ms
7,772 KB
testcase_13 AC 3 ms
5,652 KB
testcase_14 AC 7 ms
7,696 KB
testcase_15 AC 302 ms
7,908 KB
testcase_16 AC 409 ms
8,172 KB
testcase_17 AC 3 ms
5,708 KB
testcase_18 AC 3 ms
5,660 KB
testcase_19 AC 2 ms
5,712 KB
testcase_20 AC 3 ms
5,620 KB
testcase_21 AC 2 ms
5,612 KB
testcase_22 AC 2 ms
5,896 KB
testcase_23 AC 2 ms
5,500 KB
testcase_24 AC 3 ms
5,380 KB
testcase_25 AC 2 ms
5,388 KB
testcase_26 AC 213 ms
7,728 KB
testcase_27 TLE -
testcase_28 -- -
testcase_29 -- -
testcase_30 -- -
testcase_31 -- -
testcase_32 -- -
testcase_33 -- -
testcase_34 -- -
testcase_35 -- -
testcase_36 -- -
testcase_37 -- -
testcase_38 -- -
testcase_39 -- -
testcase_40 -- -
testcase_41 -- -
testcase_42 -- -
testcase_43 -- -
testcase_44 -- -
testcase_45 -- -
testcase_46 -- -
testcase_47 -- -
testcase_48 -- -
testcase_49 -- -
testcase_50 -- -
testcase_51 -- -
testcase_52 -- -
testcase_53 -- -
testcase_54 -- -
testcase_55 -- -
testcase_56 -- -
testcase_57 -- -
testcase_58 -- -
testcase_59 -- -
testcase_60 -- -
testcase_61 -- -
testcase_62 -- -
testcase_63 -- -
testcase_64 -- -
testcase_65 -- -
testcase_66 -- -
testcase_67 -- -
testcase_68 -- -
testcase_69 -- -
testcase_70 -- -
testcase_71 -- -
testcase_72 -- -
testcase_73 -- -
testcase_74 -- -
testcase_75 -- -
testcase_76 -- -
testcase_77 -- -
testcase_78 -- -
testcase_79 -- -
testcase_80 -- -
testcase_81 -- -
testcase_82 -- -
testcase_83 -- -
testcase_84 -- -
testcase_85 -- -
testcase_86 -- -
testcase_87 -- -
testcase_88 -- -
testcase_89 -- -
testcase_90 -- -
testcase_91 -- -
testcase_92 -- -
testcase_93 -- -
testcase_94 -- -
testcase_95 -- -
testcase_96 -- -
testcase_97 -- -
testcase_98 -- -
testcase_99 -- -
testcase_100 -- -
testcase_101 -- -
testcase_102 -- -
testcase_103 -- -
testcase_104 -- -
testcase_105 -- -
testcase_106 -- -
testcase_107 -- -
testcase_108 -- -
testcase_109 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

#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 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 ((i & i - 1) == 0) {
      dp[i][prod[i] - 1] = true;
      continue;
    }
    rep(j, N) if (i >> j & 1) {
      for (ll k = prod[i ^ 1 << j] - 1; (k + 1) * prod[U ^ i ^ (1 << j)] - 1 <= X; 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;
}

bool dfs(int x, int u) {
  if ((double)(clock() - beg) / CLOCKS_PER_SEC >= 1.0) {
    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