結果

問題 No.941 商とあまり
ユーザー 👑 emthrmemthrm
提出日時 2019-12-05 01:38:44
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 376 ms / 2,000 ms
コード長 2,400 bytes
コンパイル時間 1,384 ms
コンパイル使用メモリ 131,444 KB
実行使用メモリ 5,324 KB
最終ジャッジ日時 2023-08-21 12:46:53
合計ジャッジ時間 13,058 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 61 ms
4,376 KB
testcase_01 AC 24 ms
4,380 KB
testcase_02 AC 24 ms
4,380 KB
testcase_03 AC 23 ms
4,380 KB
testcase_04 AC 24 ms
4,376 KB
testcase_05 AC 24 ms
4,376 KB
testcase_06 AC 23 ms
4,380 KB
testcase_07 AC 36 ms
4,376 KB
testcase_08 AC 36 ms
4,376 KB
testcase_09 AC 35 ms
4,376 KB
testcase_10 AC 43 ms
4,380 KB
testcase_11 AC 40 ms
4,380 KB
testcase_12 AC 38 ms
4,380 KB
testcase_13 AC 24 ms
4,376 KB
testcase_14 AC 325 ms
5,000 KB
testcase_15 AC 376 ms
5,044 KB
testcase_16 AC 361 ms
5,324 KB
testcase_17 AC 24 ms
4,376 KB
testcase_18 AC 24 ms
4,376 KB
testcase_19 AC 24 ms
4,376 KB
testcase_20 AC 24 ms
4,380 KB
testcase_21 AC 23 ms
4,376 KB
testcase_22 AC 24 ms
4,376 KB
testcase_23 AC 2 ms
4,380 KB
testcase_24 AC 2 ms
4,380 KB
testcase_25 AC 2 ms
4,380 KB
testcase_26 AC 57 ms
4,380 KB
testcase_27 AC 73 ms
4,376 KB
testcase_28 AC 252 ms
4,620 KB
testcase_29 AC 304 ms
4,616 KB
testcase_30 AC 306 ms
4,612 KB
testcase_31 AC 184 ms
4,380 KB
testcase_32 AC 32 ms
4,376 KB
testcase_33 AC 24 ms
4,376 KB
testcase_34 AC 24 ms
4,380 KB
testcase_35 AC 24 ms
4,380 KB
testcase_36 AC 42 ms
4,376 KB
testcase_37 AC 45 ms
4,376 KB
testcase_38 AC 40 ms
4,380 KB
testcase_39 AC 23 ms
4,376 KB
testcase_40 AC 23 ms
4,380 KB
testcase_41 AC 24 ms
4,380 KB
testcase_42 AC 23 ms
4,380 KB
testcase_43 AC 39 ms
4,376 KB
testcase_44 AC 39 ms
4,376 KB
testcase_45 AC 114 ms
4,384 KB
testcase_46 AC 86 ms
4,376 KB
testcase_47 AC 150 ms
4,380 KB
testcase_48 AC 23 ms
4,376 KB
testcase_49 AC 180 ms
4,376 KB
testcase_50 AC 58 ms
4,380 KB
testcase_51 AC 74 ms
4,376 KB
testcase_52 AC 45 ms
4,380 KB
testcase_53 AC 61 ms
4,376 KB
testcase_54 AC 155 ms
4,384 KB
testcase_55 AC 148 ms
4,380 KB
testcase_56 AC 151 ms
4,380 KB
testcase_57 AC 23 ms
4,376 KB
testcase_58 AC 24 ms
4,376 KB
testcase_59 AC 35 ms
4,380 KB
testcase_60 AC 35 ms
4,376 KB
testcase_61 AC 34 ms
4,376 KB
testcase_62 AC 25 ms
4,380 KB
testcase_63 AC 25 ms
4,376 KB
testcase_64 AC 24 ms
4,376 KB
testcase_65 AC 25 ms
4,376 KB
testcase_66 AC 48 ms
4,376 KB
testcase_67 AC 25 ms
4,380 KB
testcase_68 AC 46 ms
4,376 KB
testcase_69 AC 25 ms
4,376 KB
testcase_70 AC 25 ms
4,376 KB
testcase_71 AC 65 ms
4,376 KB
testcase_72 AC 65 ms
4,376 KB
testcase_73 AC 25 ms
4,380 KB
testcase_74 AC 25 ms
4,376 KB
testcase_75 AC 25 ms
4,380 KB
testcase_76 AC 25 ms
4,380 KB
testcase_77 AC 25 ms
4,380 KB
testcase_78 AC 25 ms
4,376 KB
testcase_79 AC 25 ms
4,376 KB
testcase_80 AC 25 ms
4,376 KB
testcase_81 AC 25 ms
4,380 KB
testcase_82 AC 24 ms
4,376 KB
testcase_83 AC 25 ms
4,376 KB
testcase_84 AC 25 ms
4,380 KB
testcase_85 AC 25 ms
4,376 KB
testcase_86 AC 24 ms
4,376 KB
testcase_87 AC 25 ms
4,376 KB
testcase_88 AC 25 ms
4,384 KB
testcase_89 AC 25 ms
4,380 KB
testcase_90 AC 25 ms
4,376 KB
testcase_91 AC 25 ms
4,376 KB
testcase_92 AC 25 ms
4,380 KB
testcase_93 AC 25 ms
4,380 KB
testcase_94 AC 25 ms
4,376 KB
testcase_95 AC 25 ms
4,376 KB
testcase_96 AC 25 ms
4,380 KB
testcase_97 AC 24 ms
4,376 KB
testcase_98 AC 23 ms
4,376 KB
testcase_99 AC 24 ms
4,376 KB
testcase_100 AC 24 ms
4,380 KB
testcase_101 AC 24 ms
4,380 KB
testcase_102 AC 24 ms
4,380 KB
testcase_103 AC 24 ms
4,380 KB
testcase_104 AC 1 ms
4,376 KB
testcase_105 AC 1 ms
4,376 KB
testcase_106 AC 2 ms
4,380 KB
testcase_107 AC 2 ms
4,376 KB
testcase_108 AC 2 ms
4,380 KB
testcase_109 AC 2 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <chrono>
#define _USE_MATH_DEFINES
#include <cmath>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <tuple>
#include <utility>
#include <vector>
using namespace std;

#define FOR(i,m,n) for(int i=(m);i<(n);++i)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) (v).begin(),(v).end()

const int INF = 0x3f3f3f3f;
const long long LINF = 0x3f3f3f3f3f3f3f3fLL;
const double EPS = 1e-8;
const int MOD = 1000000007;
// const int MOD = 998244353;
const int dy[] = {1, 0, -1, 0}, dx[] = {0, -1, 0, 1};
// const int dy[] = {1, 1, 0, -1, -1, -1, 0, 1},
//           dx[] = {0, -1, -1, -1, 0, 1, 1, 1};

struct IOSetup {
  IOSetup() {
    cin.tie(nullptr);
    ios_base::sync_with_stdio(false);
    cout << fixed << setprecision(20);
    cerr << fixed << setprecision(10);
  }
} iosetup;
/*-------------------------------------------------*/
void output(const vector<bool> &ans) {
  for (bool e : ans) cout << e;
  cout << '\n';
  exit(0);
}

int main() {
  int n, x; cin >> n >> x;
  vector<int> a(n); REP(i, n) cin >> a[i];
  vector<bool> ans(x, false);
  if (n == 1) {
    if (a[0] <= x) ans[a[0] - 1] = true;
    output(ans);
  }
  if (n >= 19) output(ans);
  long long lb = 1;
  REP(i, n) {
    lb *= a[i] + 1;
    if (x < lb - 1) output(ans);
  }
  if (count(ALL(a), 1) > 0) {
    FOR(i, lb - 1 - 1, x) ans[i] = true;
    output(ans);
  }
  vector<int> p(n + 1, 1);
  FOR(i, 1, n + 1) p[i] = p[i - 1] * 3;
  vector<vector<bool> > dp(1 << n);
  REP(i, 1 << n) dp[i].assign(x / p[n - __builtin_popcount(i)] + 1, false);
  REP(i, n) {
    if (a[i] < dp[1 << i].size()) dp[1 << i][a[i]] = true;
  }
  FOR(i, 1, 1 << n) REP(j, n) {
    if (i >> j & 1) continue;
    int nx_i = i | (1 << j);
    vector<bool> tmp(dp[nx_i].size(), false);
    REP(k, dp[i].size()) {
      if (dp[i][k]) {
        long long par = (1LL + k) * (a[j] + 1) - 1;
        if (par < tmp.size()) tmp[par] = true;
      }
    }
    REP(k, tmp.size()) {
      if (tmp[k]) {
        dp[nx_i][k] = true;
        if (k + a[j] < tmp.size()) tmp[k + a[j]] = true;
      }
    }
  }
  FOR(j, 1, x + 1) ans[j - 1] = dp[(1 << n) - 1][j];
  output(ans);
}
0