結果
問題 |
No.941 商とあまり
|
ユーザー |
![]() |
提出日時 | 2019-09-06 11:47:20 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
TLE
|
実行時間 | - |
コード長 | 1,296 bytes |
コンパイル時間 | 1,983 ms |
コンパイル使用メモリ | 185,384 KB |
実行使用メモリ | 1,584,944 KB |
最終ジャッジ日時 | 2024-11-21 04:45:06 |
合計ジャッジ時間 | 287,359 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | WA * 5 MLE * 1 |
other | WA * 8 TLE * 35 MLE * 61 |
ソースコード
#include <bits/stdc++.h> /* TLE */ bool solve(int n, int x, const std::vector<int> &a_) { auto a = a_; std::sort(a.begin(), a.end()); std::vector<std::vector<int> > que; que.push_back({x}); while (que.size()) { if (que.begin()->size() == a.size()) { for (auto &i : que) if (i == a) return true; return false; } std::vector<std::vector<int> > next; for (auto &i : que) { for (int j = 0; j < (int) i.size(); j++) { for (int k = 1; k < i[j]; k++) { if (i[j] % k == 0) continue; auto tmp = i; tmp.push_back(tmp[j] / k); tmp[j] %= k; std::sort(tmp.begin(), tmp.end()); bool cancel = false; for (int l = 0; l < (int) tmp.size(); l++) { if (tmp[l] < a[l]) { cancel = true; break; } } if (!cancel) next.push_back(tmp); } } } std::sort(next.begin(), next.end()); next.erase(std::unique(next.begin(), next.end()), next.end()); std::swap(que, next); } return false; } int main() { int n, x; scanf("%d%d", &n, &x); std::vector<int> a(n); for (int i = 0; i < n; i++) scanf("%d", &a[i]); clock_t r0 = clock(); std::cout << (solve(n, x, a) ? "YES" : "NO") << std::endl; clock_t r1 = clock(); std::cerr << (double) (r1 - r0) * 1000 / CLOCKS_PER_SEC << "ms" << std::endl; return 0; }