QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#200560#5040. Dirichlet $k$-th rootvanthoci#WA 2ms8464kbC++173.4kb2023-10-04 17:31:212023-10-04 17:31:22

Judging History

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

  • [2023-10-04 17:31:22]
  • 评测
  • 测评结果:WA
  • 用时:2ms
  • 内存:8464kb
  • [2023-10-04 17:31:21]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
using i64 = long long;

inline char nc() { static char buf[1000000], * p1 = buf, * p2 = buf; return p1 == p2 && (p2 = (p1 = buf) + fread(buf, 1, 1000000, stdin), p1 == p2) ? EOF : *p1++; }
inline void read(int &sum) { char ch = nc(); sum = 0; while (!(ch >= '0' && ch <= '9')) ch = nc(); while (ch >= '0' && ch <= '9') sum = (sum << 3ll) + (sum << 1ll) + (ch - 48ll), ch = nc(); }

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 + 10;
const int mod = 998244353;
vector<int> fac[N];

int n, k, x;
int called = 0;
int a[N], b[N];
int AK[N], F[N], G[N];

unordered_map<int, int> INV;
int add(const int &a, const int& b) {
    return (a + b >= mod) ? (a + b - mod) : (a + b);
}
int mul(const int &a, const int& b) {
    return 1LL * a * b % mod;
}
int power(int a, int b) {
    int res = 1;
    for (; b; b >>= 1, a = mul(a, a)) {
        if (b & 1) res = mul(res, a);
    }
    return res;
}
int inv(const int& a) {
    if(INV.count(a)) return INV[a];
    return INV[a] = power(a, mod - 2);
}
int Div(const int &a, const int& b) {
    return mul(a, inv(b));
}

#include<bits/extc++.h>
unordered_map<int, int> occ;

int nowval = 0;
void calc() {
    int g = 1, fm = 1, sum = 0;
    for (auto [d, t] : occ) {
        if(!t) continue;
        g = mul(g, power(a[d], t));
        fm = mul(fm, G[t]);
        sum += t;
    }

    nowval = add(nowval, mul(mul(AK[sum], fm), g)); 
}

void dfs(int now, int dep, int res) {
    // debug(now, dep, res, x);
    if (dep == k - 1 || res == 1) {
        if (res != x) {
            if (res != 1) occ[res]++;
            calc();
            if (res != 1) {
                occ[res]--;
                if(!occ[res]) occ.erase(res);
            }
        }
        return ;
    }
    for (int i = now; i < fac[x].size() - 1; i++) {
        int& d = fac[x][i];
        if (res % d) continue;
        occ[d] ++;
        dfs(i, dep + 1, res / d);
        occ[d] --;
        if(!occ[d]) occ.erase(d);
    }
}

signed main() {
    // ios::sync_with_stdio(0), cin.tie(0);
    Time_Start;
    
    read(n), read(k);
    for (int i = 1; i <= n; i++) read(b[i]);
    for (int i = 2; i <= n; i++) {
        for (int j = i; j <= n; j += i) {
            fac[j].push_back(i);
        }
    }

    AK[0] = F[0] = 1;
    for (int i = 1; i < N; i++) {
        AK[i] = mul(AK[i-1], k - i + 1);
        F[i] = mul(F[i-1], i);
    } 
    G[N-1] = inv(F[N-1]);
    for (int i = N - 2; i >= 0; i--) G[i] = mul(G[i+1], i+1);

    a[1] = 1;
    for (x = 2; x <= n; x++) {
        occ.clear();
        nowval = 0;
        dfs(0, 0, x);
        a[x] = (b[x] % k - nowval);
        if (a[x] < 0) a[x] += mod;
        a[x] = Div(a[x], k);
    }
    for (int i = 1; i <= n; i++) cout << a[i] << ' ';

    debug(called);
    Time_End;
    return 0;
}

詳細信息

Test #1:

score: 0
Wrong Answer
time: 2ms
memory: 8464kb

input:

5 2
1 8 4 26 6

output:

1 0 0 0 0 

result:

wrong answer 2nd numbers differ - expected: '4', found: '0'