結果
| 問題 |
No.941 商とあまり
|
| コンテスト | |
| ユーザー |
QCFium
|
| 提出日時 | 2019-09-06 08:44:38 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
TLE
|
| 実行時間 | - |
| コード長 | 1,326 bytes |
| コンパイル時間 | 2,216 ms |
| コンパイル使用メモリ | 185,276 KB |
| 実行使用メモリ | 127,012 KB |
| 最終ジャッジ日時 | 2024-11-21 04:40:15 |
| 合計ジャッジ時間 | 300,316 ms |
|
ジャッジサーバーID (参考情報) |
judge1 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | WA * 6 |
| other | WA * 7 TLE * 97 |
ソースコード
#include <bits/stdc++.h>
/* TLE */
struct vector_hash {
size_t operator()(const std::vector<int>& v) const {
std::hash<int> hasher;
size_t seed = 0;
for (int i : v) {
seed ^= hasher(i) + 0x9e3779b9 + (seed<<6) + (seed>>2);
}
return seed;
}
};
bool solve(int n, int x, const std::vector<int> &a_) {
auto a = a_;
std::sort(a.begin(), a.end());
std::unordered_set<std::vector<int>, vector_hash> que;
que.insert({x});
while (que.size()) {
if (que.begin()->size() == a.size()) {
for (auto &i : que) if (i == a) return true;
return false;
}
std::unordered_set<std::vector<int>, vector_hash> 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());
next.insert(tmp);
}
}
}
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;
}
QCFium