QOJ.ac
QOJ
ID | 提交记录ID | 题目 | Hacker | Owner | 结果 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|
#1091 | #688133 | #9527. A Brand New Geometric Problem | marvinthang | propane | Success! | 2024-10-31 16:13:46 | 2024-10-31 16:13:54 |
詳細信息
Extra Test:
Wrong Answer
time: 3ms
memory: 3632kb
input:
100000 10000 9340531200 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 ...
output:
90097
result:
wrong answer 1st lines differ - expected: '90093', found: '90097'
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#688133 | #9527. A Brand New Geometric Problem | propane | WA | 19ms | 4912kb | C++20 | 3.0kb | 2024-10-29 23:36:30 | 2024-11-06 13:21:48 |
answer
#include<iostream>
#include<cstring>
#include<vector>
#include<cmath>
#include<algorithm>
using namespace std;
using LL = long long;
int cnt;
int c[10005];
int id1[100005], id2[100005];
int get(LL x){
if (x <= 100000) return id1[x];
else return id2[10'000'000'000 / x];
}
int main(){
#ifdef LOCAL
freopen("data.in", "r", stdin);
freopen("data.out", "w", stdout);
#endif
cin.tie(0);
cout.tie(0);
ios::sync_with_stdio(0);
int n; LL S, M;
cin >> n >> S >> M;
vector<LL> factor;
for(LL i = 1; i * i <= M; i++){
if (M % i == 0){
factor.push_back(i);
if (i * i != M){
factor.push_back(M / i);
}
}
}
sort(factor.begin(), factor.end(), greater<>());
factor.pop_back();
reverse(factor.begin(), factor.end());
while(!factor.empty() and factor.back() > S) factor.pop_back();
reverse(factor.begin(), factor.end());
for(int i = 0; i < factor.size(); i++){
LL x = factor[i];
if (x <= 100000) id1[x] = i;
else id2[10'000'000'000 / x] = i;
}
int cnt1 = 0;
for(int i = 0; i < n; i++){
LL x;
cin >> x;
if (M % x != 0) continue;
if (x == 1) cnt1 += 1;
else c[get(x)] += 1;
}
if (cnt1 > S){
LL keep = 0;
LL t = M, ss = 0, tot = 0;
for(LL i = 2; i * i <= t; i++){
if (t % i == 0){
int v = 0;
while(t % i == 0){
ss += i;
t /= i;
v += 1;
}
if (i <= S) keep += min(v, c[get(i)]);
tot += v;
}
}
if (t > 1 and t <= S){
ss += t;
if (t <= S) keep += min(1, c[get(S)]);
tot += 1;
}
if (ss > S){
cout << -1 << '\n';
return 0;
}
tot -= keep;
keep += S - ss;
cout << n - keep + tot << '\n';
return 0;
}
const LL INF = 1e18;
LL ans = INF;
auto dfs = [&](auto &&dfs, int u, LL val, LL sum, int num){
if (S - sum - M / val - 35 > ans) return;
if (val == M){
ans = min(ans, abs(S - sum - cnt1) + num);
return;
}
if (u == factor.size()) return;
vector<LL> p1{val}, p2{sum};
{
while(1){
if (M / p1.back() % factor[u] == 0 and p2.back() + factor[u] <= S){
p1.push_back(p1.back() * factor[u]);
p2.push_back(p2.back() + factor[u]);
}
else break;
}
}
for(int i = p1.size() - 1; i >= 0; i--){
if (i <= c[u]) dfs(dfs, u + 1, p1[i], p2[i], num - i);
else dfs(dfs, u + 1, p1[i], p2[i], num - c[u] + (i - c[u]));
}
};
dfs(dfs, 0, 1, 0, n - cnt1);
if (ans > INF / 2) cout << -1 << '\n';
else cout << ans << '\n';
}