結果
問題 | No.941 商とあまり |
ユーザー |
![]() |
提出日時 | 2019-12-04 06:33:19 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 2,089 bytes |
コンパイル時間 | 2,601 ms |
コンパイル使用メモリ | 205,320 KB |
最終ジャッジ日時 | 2025-01-08 07:42:53 |
ジャッジサーバーID (参考情報) |
judge3 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 6 |
other | AC * 97 WA * 3 TLE * 4 |
ソースコード
#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; }