QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#199705 | #5050. Value | vanthoci# | WA | 1ms | 7032kb | C++17 | 2.0kb | 2023-10-04 13:47:11 | 2023-10-04 13:47:11 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
using i64 = long long;
template<class A> string to_string(A v) {
string res = "{";
for (const auto &x: v) res += to_string(x) + ", ";
return res.substr(0, res.size() - 2) + "}";
}
void debug_out() { cerr << "\n"; }
template<class H, class... T> void debug_out(H h, T... t) {
cerr << " " << to_string(h); debug_out(t...);
}
#define debug(...) cerr << "[" << #__VA_ARGS__ << "] : "; debug_out(__VA_ARGS__)
#define Time_Start clock_t start = clock()
#define Time_End clock_t end = clock();\
double time_elapsed = (double)(end - start) / CLOCKS_PER_SEC;\
cerr << "time elapsed :" << time_elapsed << "s\n"
const int N = 1E5;
vector<int> pre[N + 10];
bool vis[N + 10];
int cnt[N + 10];
int a[N + 10], b[N + 10];
int n;
i64 cal(const vector<int>& link){
int m = link.size();
i64 cnt = 0;
for (int i = 0; i < (1 << m); i++) {
i64 res = 0;
// debug(i);
for (int j = 0; j < m; j++) {
if (i & (1 << j)) res += a[link[j]];
for (int k = 0; k < j; k ++){
if (not (i & (1 << k))) continue;
if ((j + 1) % (k + 1) == 0) res -= b[link[j]];
}
}
// debug(res);
cnt = max(cnt, res);
}
return cnt;
}
void solve() {
cin >> n;
for (int i = 2; i <= n; i++) {
if(vis[i]) continue;
for (i64 j = i; j <= n; j *= i) {
pre[i].push_back(j);
vis[j] = true;
}
}
for (int i = 1; i <= n; i++) cin >> a[i];
for (int i = 1; i <= n; i++) cin >> b[i];
i64 ans = a[1];
for (int i = 2; i <= n; i++) {
if(pre[i].empty()) continue;
ans += cal(pre[i]);
// debug(i, cal(pre[2]), pre[2]);
}
cout << ans << '\n';
}
signed main() {
ios::sync_with_stdio(0), cin.tie(0);
Time_Start;
int T; T = 1;
// cin >> T;
while (T--) solve();
Time_End;
return 0;
}
详细
Test #1:
score: 100
Accepted
time: 1ms
memory: 7032kb
input:
4 1 1 1 2 1 1 1 1
output:
4
result:
ok 1 number(s): "4"
Test #2:
score: 0
Accepted
time: 1ms
memory: 6136kb
input:
4 1 1 1 1 1 1 1 2
output:
3
result:
ok 1 number(s): "3"
Test #3:
score: 0
Accepted
time: 1ms
memory: 6324kb
input:
1 4 10
output:
4
result:
ok 1 number(s): "4"
Test #4:
score: 0
Accepted
time: 0ms
memory: 6324kb
input:
2 6 8 2 4
output:
14
result:
ok 1 number(s): "14"
Test #5:
score: -100
Wrong Answer
time: 0ms
memory: 6328kb
input:
5 1 6 10 5 1 7 1 5 10 9
output:
17
result:
wrong answer 1st numbers differ - expected: '18', found: '17'