QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#544532 | #6512. Completely Multiplicative Function | haze# | WA | 1032ms | 12240kb | C++20 | 3.5kb | 2024-09-02 18:25:29 | 2024-09-02 18:25:29 |
Judging History
answer
/*
Author: Haze
2024/9/2
*/
#include <bits/stdc++.h>
#define irep(i, l, r) for(int i = (l); i <= (r); ++ i)
#define drep(i, r, l) for(int i = (r); i >= (l); -- i)
#define IOS ios::sync_with_stdio(false), cin.tie(nullptr);
using namespace std;
typedef long long ll;
#define int long long
inline ll readL() {
ll s = 0;
bool fl = false;
char ch = (char) getchar();
while (!isdigit(ch)) {
if (ch == '-')fl = true;
ch = (char) getchar();
}
while (isdigit(ch)) {
s = s * 10 + (ch ^ 48);
ch = (char) getchar();
}
return fl ? -s : s;
}
inline int read() {
return (int) (readL());
}
const int mod = 1000000000 + 7;
const int itinf = 1000000999;
const ll llinf = 2e18;
const int N = 1000099;
int isp[N];
vector<int> pri;
map<array<int, 2>, int> F;
void solve(ll n, ll k) {
if ((n - k) & 1) {
cout << "-1\n";
return;
}
ll g = (n - k) / 2;
vector<int> key(n + 1, 1);
vector<array<int, 2>> choice;
for (int i = 2; i <= n; ++i) {
if (i * i > n and isp[i] == 0) {
choice.push_back({i, n / i});
if (g >= n / i) {
// cerr << i << ' ' << g << ' ' << n / i << endl;
int fl = -1;
for (int c = i; c <= n; c += i) {
key[c] = fl;
fl *= -1;
}
g -= n / i;
}
}
}
if (g > 0) {
vector<int>arr(n + 1);
ll mask = F[{n, k}];
// cerr << n << ' ' << k << ' ' << mask << endl;
for (int i = 0; pri[i] <= n; ++i) {
if (mask & (1 << i)) {
arr[pri[i]] = -1;
} else arr[pri[i]] = 1;
}
arr[1] = 1;
irep(i, 1, n) {
for (int j = 2; j <= i; ++j) {
if (isp[i] == 0){
if(arr[i] == 0)arr[i] = 1;
break;
}
if (i % j == 0) {
arr[i] = arr[j] * arr[i / j];
break;
}
}
cout << arr[i] << ' ';
}
cout << '\n';
}
else{
irep(i, 1, n){
cout << key[i] << " \n"[i == n];
}
}
}
signed main() {
// IOS
irep(i, 2, 1000000) {
if (isp[i] == 0) {
pri.push_back(i);
}
for (int x: pri) {
if (1ll * x * i > 1000000)break;
isp[x * i] = 1;
}
}
std::mt19937 rnd(std::chrono::system_clock::now().time_since_epoch().count());
// int cc = 100000;
irep(mask, 0, 1 << 16) {
vector<int> arr(201, 0);
for (int i = 0; pri[i] < 200; ++i) {
if (mask & (1 << i)) {
arr[pri[i]] = -1;
} else arr[pri[i]] = 1;
}
arr[1] = 1;
ll sum = 0;
irep(i, 1, 200) {
for (int j = 2; j <= i; ++j) {
if (isp[i] == 0){
if(arr[i] == 0)arr[i] = 1;
break;
}
if (i % j == 0) {
arr[i] = arr[j] * arr[i / j];
break;
}
}
sum += arr[i];
F[{i, sum}] = mask;
}
}
int T = read();
irep(i, 1, T){
ll n, k;
cin >> n >> k;
solve(n, k);
}
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 1006ms
memory: 12120kb
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: 1032ms
memory: 12240kb
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 1 1 1...
result:
wrong answer sum of f is not k (test case 21)