QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#370139 | #6512. Completely Multiplicative Function | PlentyOfPenalty# | WA | 23ms | 11488kb | C++20 | 2.4kb | 2024-03-28 22:18:55 | 2024-03-28 22:18:56 |
Judging History
answer
#include <bits/stdc++.h>
#ifndef popteam
#define endl '\n'
#endif
#define all(x) begin(x), end(x)
using namespace std;
const int N = 1e6, L = 20;
int T, n, k, p[N + 10], sz, ip[N + 10], ar[N + 10], v[N + 10], m, nd, f[N + 10];
vector<vector<int>> ans[L + 1];
int stk[L + 9];
void dfs(int u, int s, int n, vector<vector<int>> &ans) {
// cerr << "dfs " << u << " " << s << " " << n << endl;
if (u > n) {
if (s >= 0 && ans[s].empty()) {
ans[s].resize(n);
// cerr << "find n=" << n << " s=" << s << endl;
for (int i = 1; i <= n; i++) {
ans[s][i - 1] = stk[i];
// cerr << stk[i] << " \n"[i == n];
}
}
return;
}
if (ip[u]) {
for (stk[u] = -1; stk[u] <= 1; stk[u] += 2) {
dfs(u + 1, s + stk[u], n, ans);
}
} else {
for (int i = 1;; i++)
if (u % p[i] == 0) {
stk[u] = stk[p[i]] * stk[u / p[i]];
dfs(u + 1, s + stk[u], n, ans);
break;
}
}
}
void solve(int n, vector<vector<int>> &ans) {
ans.resize(n + 1);
stk[1] = 1;
dfs(2, 1, n, ans);
}
int main() {
#ifdef popteam
freopen("L.in", "r", stdin);
#endif
cin.tie(0)->sync_with_stdio(0);
cin >> T;
for (int i = 2; i <= N; ++i) {
if (!p[i]) p[++sz] = i, ip[i] = 1;
for (int j = 1; j <= sz && i * p[j] <= N; ++j) {
p[i * p[j]] = 1;
if (i % p[j] == 0) break;
}
}
// cerr << ip[1] << " " << ip[2] << " " << ip[3] << " " << ip[4] << endl;
// cerr << p[1] << " " << p[2] << " " << p[3] << endl;
for (int i = 1; i <= 20; i++) {
solve(i, ans[i]);
}
while (T--) {
cin >> n >> k;
if (n <= L) {
if (ans[n][k].empty()) {
cout << -1 << endl;
} else {
for (int i = 0; i < ans[n][k].size(); i++) cout << ans[n][k][i] << " \n"[i + 1 == ans[n][k].size()];
}
continue;
}
if ((n & 1) != (k & 1)) {
cout << "-1\n";
continue;
}
nd = (n - k >> 1);
m = 0;
for (int i = sqrt(n) + 1; i <= n; ++i)
if (ip[i] && 1ll * i * i > n) {
ar[++m] = i, v[m] = n / i;
}
for (int i = 1; i <= n; ++i) f[i] = 1;
for (int i = 1; i <= m; ++i)
if (v[i] <= nd) {
nd -= v[i];
for (int j = ar[i]; j <= n; j += ar[i]) f[j] = -1;
}
// assert(!nd);
if (!nd)
for (int i = 1; i <= n; ++i) cout << f[i] << " \n"[i == n];
else
cout << "-1" << endl;
}
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 8ms
memory: 11488kb
input:
4 4 2 10 0 10 1 10 10
output:
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
result:
ok ok (4 test cases)
Test #2:
score: -100
Wrong Answer
time: 23ms
memory: 11424kb
input:
11475 1 0 1 1 2 0 2 1 2 2 3 0 3 1 3 2 3 3 4 0 4 1 4 2 4 3 4 4 5 0 5 1 5 2 5 3 5 4 5 5 6 0 6 1 6 2 6 3 6 4 6 5 6 6 7 0 7 1 7 2 7 3 7 4 7 5 7 6 7 7 8 0 8 1 8 2 8 3 8 4 8 5 8 6 8 7 8 8 9 0 9 1 9 2 9 3 9 4 9 5 9 6 9 7 9 8 9 9 10 0 10 1 10 2 10 3 10 4 10 5 10 6 10 7 10 8 10 9 10 10 11 0 11 1 11 2 11 3 11...
output:
-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 ...
result:
wrong answer ans finds the answer, but out doesn't (test case 326)