QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#636013#6512. Completely Multiplicative FunctionHTensorWA 650ms49144kbC++232.7kb2024-10-12 21:49:212024-10-12 21:49:22

Judging History

你现在查看的是最新测评结果

  • [2024-10-12 21:49:22]
  • 评测
  • 测评结果:WA
  • 用时:650ms
  • 内存:49144kb
  • [2024-10-12 21:49:21]
  • 提交

answer

#include <bits/stdc++.h>
#define dd(x) cout << #x << "\n"
#define d(x) cout << #x  << ": " << x << "\n"
#define SZ(x) ((int)(x).size())
using namespace std;
#define int long long
using pii = pair<int, int>;
using vpii = vector<pii>;
using vi = vector<int>;
using vii = vector<vector<int>>;
using a3 = array<int, 3>;
using ll = long long;
const int inf = 0x3f3f3f3f3f3f3f3fLL;

#define MULTI_TEST

const int N = 1e6 + 6;
int isnt[N], ist[N], f[N];
vector<int> prime, p2;
int px[100];

void sieve(int n) {
    isnt[1] = isnt[0] = 1;
    for(int i = 2; i <= n; i++) {
        if(!isnt[i]) prime.push_back(i);
        for(auto p : prime) {
            if(i * p > n) break;
            isnt[i * p] = 1;
            if(i % p == 0) break;
        }
    }
}

void calc(int n) {
    f[1] = 1;
    ist[1] = ist[0] = 1;
    for(int i = 2; i <= n; i++) {
        if(!ist[i]) {
            p2.push_back(i);
            if(i <= 71) {
                f[i] = px[i];
            }
        }
        for(auto p : p2) {
            if(i * p > n) break;
            ist[i * p] = 1;

            if(p > 71) f[i * p] = f[i];
            else f[i * p] = f[i] * px[p];

            if(i % p == 0) break;
        }
    };
}

void clear(int n) {
    for(int i = 1; i <= n; i++) {
        f[i] = 1;
        ist[1] = 0;
    }
}

void solve() {
    int n, k; cin >> n >> k;
    if((k + n) & 1) {
        cout << "-1" << "\n";
        return ;
    }
    clear(n);

    for(int i = 1; i <= 80; i++) px[i] = 1;

    int cnt = 0;
    for(int i = n / 2 + 1; i <= n; i++) {
        if(!isnt[i]) ++cnt;
    }

    vector<int> pp{2,3,5,7,11,13,17,19,23,29,31,37,41,43,47,53,59,61,67,71};

    for(int i = 0; i < 20; i++) {
        if(pp[i] > n) break;
        px[pp[i]] = -1;
        calc(n);
        int now = accumulate(f + 1, f + n + 1, 0);
        clear(n);

        if(now < k) {
            px[pp[i]] = 1;
        }
    }

    calc(n);
    int now = accumulate(f + 1, f + n + 1, 0);
    
    int dis = (now - k) / 2;
    
    assert(dis >= 0);
    if(dis > 0) {
        for(int i = n / 2 + 1; i <= n; i++) {
            if(!isnt[i] && f[i] == 1) {
                f[i] = -1;
                cnt -= 2;
                if(cnt <= 0) break;
            }
        }
    }

    // now = accumulate(f + 1, f + n + 1, 0);
    // assert(now == k);

    
    for(int i = 1; i <= n; i++) {
        cout << f[i] << " ";
    }
    clear(n);
    cout << "\n";
}

signed main() {
    sieve(1e6);
    ios::sync_with_stdio(false); cin.tie(0);

#ifdef MULTI_TEST
    int T; cin >> T;
#else
    int T = 1;
#endif
    while(T--) solve();
    return 0;
}

/*
4
4 2
10 0
10 1
10 10
*/

詳細信息

Test #1:

score: 100
Accepted
time: 4ms
memory: 13820kb

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: 650ms
memory: 49144kb

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...

result:

wrong answer sum of f is not k (test case 3916)