結果
| 問題 |
No.2578 Jewelry Store
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2023-01-10 00:46:00 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 1,298 bytes |
| コンパイル時間 | 3,824 ms |
| コンパイル使用メモリ | 82,656 KB |
| 最終ジャッジ日時 | 2025-02-10 01:31:23 |
|
ジャッジサーバーID (参考情報) |
judge4 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 1 WA * 1 RE * 21 TLE * 30 MLE * 1 |
ソースコード
#include <algorithm>
#include <iostream>
#include <vector>
#include <atcoder/modint>
using mint = atcoder::modint998244353;
mint solve_naive(int32_t n, int64_t m, std::vector<int64_t> a, std::vector<int32_t> w) {
{
std::vector<int64_t> a2;
std::vector<int32_t> w2;
for (int32_t i = 0; i < n; ++i) if (m % a[i] == 0) {
a2.push_back(a[i]);
w2.push_back(w[i]);
}
a.swap(a2);
w.swap(w2);
n = a.size();
}
mint ans = 0;
for (int32_t s = 1; s < 1 << std::min(n, 30); ++s) {
mint prod = 1;
int64_t l = 1;
for (int32_t i = 0; i < n; ++i) if ((s >> i) & 1) {
l = std::lcm(l, a[i]);
prod *= w[i];
}
if (l == m) {
ans += prod;
}
}
return ans;
}
int main() {
std::ios::sync_with_stdio(false);
std::cin.tie(nullptr);
int32_t t;
int64_t m;
std::cin >> t >> m;
for (int32_t testcase = 0; testcase < t; ++testcase) {
int32_t n;
std::cin >> n;
std::vector<int64_t> a(n);
for (auto &e : a) std::cin >> e;
std::vector<int32_t> w(n);
for (auto &e : w) std::cin >> e;
std::cout << solve_naive(n, m, a, w).val() << '\n';
}
return 0;
}