QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#576397#6512. Completely Multiplicative FunctionQingyyxWA 5ms8036kbC++203.2kb2024-09-19 20:14:072024-09-19 20:14:07

Judging History

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

  • [2024-09-19 20:14:07]
  • 评测
  • 测评结果:WA
  • 用时:5ms
  • 内存:8036kb
  • [2024-09-19 20:14:07]
  • 提交

answer

#include <bits/stdc++.h>
#define ll long long
#define enl putchar('\n')
#define all(x) (x).begin(),(x).end()
#define debug(x) printf(" "#x":%d\n",x);
using namespace std;
const int MAXN = 1e6 + 5;
const int inf = 0x3f3f3f3f;
const ll INF = 0x3f3f3f3f3f3f3f3f;
const int mod = 998244353;
typedef pair<int, int> pii;
char buf[1 << 21], * p1 = buf, * p2 = buf, obuf[1 << 21], * o = obuf, of[35];
#define gc()(p1==p2&&(p2=(p1=buf)+fread(buf,1,1<<21,stdin),p1==p2)?EOF:*p1++)
inline ll qpow(ll a, ll n) { ll res = 1; while (n) { if (n & 1)res = res * a % mod; n >>= 1; a = a * a % mod; }return res; }
template <class T = int>inline T read() { T s = 0, f = 1; char c = gc(); for (; !isdigit(c); c = gc())if (c == '-')f = -1; for (; isdigit(c); c = gc())s = s * 10 + c - '0'; return s * f; }
inline void read(int* a, int n) { for (int i = 1; i <= n; ++i)a[i] = read(); }
inline int inal(char* s) { int n = 0; for (s[0] = gc(); !isalpha(s[0]); s[0] = gc()); for (; isalpha(s[n]); s[++n] = gc()); return s[n] = 0, n; }
inline void outd(auto* a, int n) { for (int i = 1; i <= n; ++i)printf("%d ", a[i]); enl; }
int n, m, q;
vector<int>p = {2, 3, 5, 7, 11, 13, 17, 19, 23};
vector<int>primes;
bool isnp[MAXN];
void init() {
    for (int i = 2; i < MAXN; ++i) {
        if (!isnp[i])primes.push_back(i);
        for (int j = 0; j < primes.size() && primes[j] * i < MAXN; ++j)
            isnp[primes[j] * i] = 1;
    }
}

int ans[MAXN];
void solve() {
    n = read(), m = read();
    if (m == n) {
        for (int i = 1; i <= n; ++i)printf("1 "); enl;
        return;
    }
    if (m == n - 2) {
        printf("-1 ");
        for (int i = 2; i <= n; ++i)printf("1 "); enl;
        return;
    }
    if ((n + m) % 2 == 1) {
        printf("-1\n");
        return;
    }
    ans[1] = 1;
    int cnt = 0;
    for (auto p : primes)
        if (p > n)break;
        else if (p > n / 2)++cnt;
    for (int i = 0; i < 1 << 9; ++i) {
        vector<int>vec;
        for (int j = 0; j < 9; ++j)
            if (i >> j & 1)vec.push_back(p[j]);
        fill(ans + 1, ans + n + 1, 1);
        for (int i = 2; i <= n; i++) {
            for (int x : vec) {
                if (i % x == 0) {
                    ans[i] = -ans[i / x];
                    break;
                }
            }
        }
        int sum = accumulate(ans + 1, ans + n + 1, 0);
        if (sum - cnt * 2 <= m && m <= sum) {
            int t = (sum - m) / 2;
            for (int i = n / 2 + 1; i <= n && t; i++) {
                if (!isnp[i]) {
                    ans[i] = -1;
                    --t;
                }
            }
            outd(ans, n);
            return;
        }
    }
}
signed main(signed argc, char const* argv[]) {
    clock_t c1 = clock();
#ifdef LOCAL
    freopen("in.in", "r", stdin);
    freopen("out.out", "w", stdout);
#endif
    //=============================================================
    int TxT = 1;
    TxT = read();
    init();
    while (TxT--)
        solve();
    //=============================================================
#ifdef LOCAL
    end :
    cerr << "Time Used:" << clock() - c1 << "ms" << endl;
#endif
    return 0;
}

详细

Test #1:

score: 0
Wrong Answer
time: 5ms
memory: 8036kb

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:

wrong answer ans finds the answer, but out doesn't (test case 1)