QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#483212 | #6743. water235 | ucup-team052# | WA | 0ms | 4048kb | C++14 | 1.4kb | 2024-07-18 13:42:50 | 2024-07-18 13:42:50 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
typedef unsigned long long ull;
typedef long long ll;
const int md = 998244353;
inline int add(int x, int y) {
if (x + y >= md) return x + y - md;
return x + y;
}
inline int sub(int x, int y) {
if (x < y) return x - y + md;
return x - y;
}
inline int mul(int x, int y) {
return 1ull * x * y % md;
}
inline int fpow(int x, int y) {
int ans = 1;
while (y) {
if (y & 1) ans = mul(ans, x);
y >>= 1; x = mul(x, x);
}
return ans;
}
const int M = 1e6;
unordered_map <ull, int> dp;
int inv[20], T;
ull s, t;
int solve(ull n) {
if (n > t) return 0;
if (dp.count(n)) return dp[n];
vector <int> cnt(10, 0);
ull x = n;
int all = 0;
while (x) {
++cnt[x % 10];
x /= 10; ++all;
}
/*
all = 0;
for (int i = 0; i < 9; i++) {
if (cnt[i]) cnt[i] = 1;
all += cnt[i];
}
*/
int ans = 0;
for (int i = 1; i < 10; i++) {
if (cnt[i]) {
// fprintf(stderr, "n = %llu, %d %d %d %d %d\n", n, i, cnt[i], all, mul(cnt[i], inv[all]), ans);
ans = add(ans, mul(solve(n * (i + 1)) + 1, mul(cnt[i], inv[all])));
}
}
ans = mul(ans, mul(all, inv[all - cnt[0]]));
fprintf(stderr, "dp[%llu] = %d\n", n, ans);
return dp[n] = ans;
}
int main() {
for (int i = 1; i <= 19; i++) inv[i] = fpow(i, md - 2);
cin >> T;
while (T--) {
cin >> s >> t;
dp.clear();
printf("%d\n", solve(s));
}
return 0;
}
详细
Test #1:
score: 0
Wrong Answer
time: 0ms
memory: 4048kb
input:
2 1
output:
0 0
result:
wrong output format Unexpected end of file - int32 expected