結果

問題 No.941 商とあまり
ユーザー りあんりあん
提出日時 2019-12-04 06:33:19
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 2,089 bytes
コンパイル時間 2,938 ms
コンパイル使用メモリ 210,904 KB
実行使用メモリ 14,016 KB
最終ジャッジ日時 2024-05-06 19:34:59
合計ジャッジ時間 12,580 ms
ジャッジサーバーID
(参考情報)
judge2 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 822 ms
10,140 KB
testcase_01 AC 23 ms
5,376 KB
testcase_02 AC 24 ms
5,376 KB
testcase_03 AC 23 ms
5,376 KB
testcase_04 AC 23 ms
5,376 KB
testcase_05 AC 24 ms
5,376 KB
testcase_06 AC 24 ms
5,376 KB
testcase_07 AC 31 ms
5,376 KB
testcase_08 AC 31 ms
5,376 KB
testcase_09 AC 29 ms
5,376 KB
testcase_10 WA -
testcase_11 AC 121 ms
5,376 KB
testcase_12 AC 25 ms
5,376 KB
testcase_13 AC 34 ms
5,376 KB
testcase_14 AC 29 ms
5,376 KB
testcase_15 AC 30 ms
5,376 KB
testcase_16 AC 28 ms
5,376 KB
testcase_17 AC 36 ms
5,376 KB
testcase_18 AC 28 ms
5,376 KB
testcase_19 AC 28 ms
5,376 KB
testcase_20 AC 24 ms
5,376 KB
testcase_21 AC 24 ms
5,376 KB
testcase_22 AC 24 ms
5,376 KB
testcase_23 AC 2 ms
5,376 KB
testcase_24 AC 2 ms
5,376 KB
testcase_25 AC 2 ms
5,376 KB
testcase_26 WA -
testcase_27 WA -
testcase_28 AC 30 ms
5,376 KB
testcase_29 AC 114 ms
5,376 KB
testcase_30 AC 112 ms
5,376 KB
testcase_31 AC 30 ms
5,376 KB
testcase_32 AC 25 ms
5,376 KB
testcase_33 AC 23 ms
5,376 KB
testcase_34 AC 27 ms
5,376 KB
testcase_35 AC 26 ms
5,376 KB
testcase_36 AC 27 ms
5,376 KB
testcase_37 AC 28 ms
5,376 KB
testcase_38 AC 26 ms
5,376 KB
testcase_39 AC 24 ms
5,376 KB
testcase_40 AC 24 ms
5,376 KB
testcase_41 AC 23 ms
5,376 KB
testcase_42 AC 24 ms
5,376 KB
testcase_43 AC 25 ms
5,376 KB
testcase_44 AC 25 ms
5,376 KB
testcase_45 TLE -
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 P = pair<int, int>;
const int M = 1000000007;



int x;
vector<bool> ans;

void output() {
    for (bool i : ans) {
        cout << i;
    }
    cout << '\n';
}

void dfs(const vector<int>& v, int j, int s) {
    ans[s] = true;
    if (j == v.size()) return;
    for (int i = 0; s + i < x; i += v[j]) {
        if (i > 0 && j + 1 < v.size() && i % v[j + 1] == 0) break;
        dfs(v, j + 1, s + i);
    }
}


int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n;
    cin >> n >> x;
    vector<int> a(n);
    for (int i = 0; i < n; ++i) {
        cin >> a[i];
    }
    sort(a.begin(), a.end());
    long long sum = 1;
    for (int i = 0; i < n; ++i) {
        sum *= a[i] + 1;
        if (sum > M) break;
    }
    ans = vector<bool>(x);
    if (sum - 1 > x) {
        output();
        return 0;
    }
    int bs = sum - 1;
    if (n == 1) {
        ans[a[0] - 1] = true;
        output();
        return 0;
    }
    for (int i = 0; i < n; ++i) {
        for (int j = 0; bs + j <= x; j += a[i]) {
            ans[bs + j - 1] = true;
        }
    }
    if (n > 2 && a[0] > 1) {
        vector<int> b;
        for (int i = 0; i < n; ++i) {
            if (i == 0 || a[i - 1] < a[i]) {
                b.push_back(a[i]);
            }
        }
        int sz = min(b.size() < a.size() ? (int)b.size() : (int)b.size() - 1, 3);
        vector<int> f(b.size());
        for (int i = 0; i < sz; ++i) {
            f[i] = 1;
        }
        sort(f.begin(), f.end());
        do
        {
            vector<int> c;
            for (int i = 0; i < f.size(); ++i) {
                if (f[i]) c.push_back(b[i]);
            }
            do
            {
                vector<int> v(sz);
                v[0] = c[0];
                for (int i = 1; i < sz; ++i) {
                    v[i] = (v[i - 1] + 1) * c[i];
                }
                dfs(v, 0, bs - 1);
            } while (next_permutation(c.begin(), c.end()));

        } while (next_permutation(f.begin(), f.end()));
    }
    output();

    return 0;
}
0