QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#318345 | #4056. 进制转换 | chy12321 | 100 ✓ | 987ms | 266280kb | C++14 | 2.0kb | 2024-01-31 08:22:31 | 2024-01-31 08:22:32 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
constexpr int N = 30, TOTAL = 28, HALF = 14, MOD = 998244353;
char c1;
int mem[1 << 25][2], l[N], s[N], w[N];
ll n, x[N][3], y[60], z[3], cnt[N];
ll qp(ll base, ll e) {
ll res = 1;
while (e) {
if (e & 1) res = res * base % MOD;
base = base * base % MOD;
e >>= 1;
}
return res;
}
ll dp(int cur, ll S, bool add, bool lim) {
if (cur == -1) return add ? 0 : y[__builtin_popcount(S)];
if (!lim && cur < HALF && mem[s[cur] + S][add] != -1) return mem[s[cur] + S][add];
int res = 0;
for (int i = 0; i <= (lim ? w[cur] : 2); i++) for (ll t : {0, 1}) {
ll curS = S + i * cnt[cur] + (t << l[cur]);
if (add ^ (curS >= (1ll << l[cur + 1]))) continue;
curS &= (1ll << l[cur + 1]) - 1;
res = (res + dp(cur - 1, curS & ((1ll << l[cur]) - 1), t, lim & (i == w[cur])) * x[cur][i] % MOD * y[__builtin_popcount(curS >> l[cur])] % MOD * z[i]) % MOD;
}
if (!lim && cur < HALF) mem[s[cur] + S][add] = res;
return res;
}
char c2;
int main() {
// freopen("ex_conversion3.in", "r", stdin), freopen("conversion.out", "w", stdout);
ios_base::sync_with_stdio(0); cin.tie(nullptr), cout.tie(nullptr);
cerr << (&c2 - &c1) / 1024.0 / 1024 << " MiB\n";
cin >> n >> x[0][1] >> y[1] >> z[1];
y[0] = z[0] = 1, z[2] = z[1] * z[1] % MOD;
for (int i = 2; i < 60; i++) y[i] = y[i - 1] * y[1] % MOD;
cnt[0] = 1;
for (int i = 1; i <= TOTAL + 1; i++) cnt[i] = cnt[i - 1] * 3;
for (int i = 0; i < TOTAL; i++) x[i][0] = 1, x[i][1] = qp(x[0][1], cnt[i]), x[i][2] = x[i][1] * x[i][1] % MOD;
for (int i = 0; i <= TOTAL; i++) {while ((1ll << l[i]) <= cnt[i]) l[i]++; l[i + 1] = l[i];}
for (int i = 1; i <= HALF; i++) s[i] = s[i - 1] + (1 << l[i]);
for (int i = 0; i < TOTAL; i++) w[i] = (n / cnt[i]) % 3;
memset(mem, -1, sizeof(mem));
cout << (dp(TOTAL - 1, 0, 0, 1) - 1 + MOD) % MOD;
cerr << 1e3 * clock() / CLOCKS_PER_SEC << " ms\n";
return 0;
}
詳細信息
Test #1:
score: 5
Accepted
time: 7ms
memory: 266044kb
input:
9134097 778012792 263448561 839843856
output:
887680205
result:
ok 1 number(s): "887680205"
Test #2:
score: 5
Accepted
time: 16ms
memory: 266052kb
input:
9896386 2948513 263418583 271155379
output:
853292631
result:
ok 1 number(s): "853292631"
Test #3:
score: 5
Accepted
time: 7ms
memory: 266184kb
input:
9150910 827328107 842171962 39947937
output:
534921610
result:
ok 1 number(s): "534921610"
Test #4:
score: 5
Accepted
time: 927ms
memory: 266212kb
input:
9586674634211 1 1 58301262
output:
13306748
result:
ok 1 number(s): "13306748"
Test #5:
score: 5
Accepted
time: 923ms
memory: 266280kb
input:
9774917720998 1 1 609549524
output:
825025220
result:
ok 1 number(s): "825025220"
Test #6:
score: 5
Accepted
time: 910ms
memory: 266000kb
input:
9765239207265 422503033 1 719749187
output:
993518920
result:
ok 1 number(s): "993518920"
Test #7:
score: 5
Accepted
time: 898ms
memory: 266116kb
input:
9732354736444 277693641 1 501293609
output:
77844778
result:
ok 1 number(s): "77844778"
Test #8:
score: 5
Accepted
time: 20ms
memory: 266116kb
input:
9004409828 377918953 449219487 26422407
output:
110868569
result:
ok 1 number(s): "110868569"
Test #9:
score: 5
Accepted
time: 35ms
memory: 266052kb
input:
9579878149 820453354 218842704 133154415
output:
727248713
result:
ok 1 number(s): "727248713"
Test #10:
score: 5
Accepted
time: 27ms
memory: 266104kb
input:
9475807443 305433821 391589421 170059051
output:
372839725
result:
ok 1 number(s): "372839725"
Test #11:
score: 5
Accepted
time: 226ms
memory: 265992kb
input:
484758270277 372146623 410538257 35340632
output:
575284574
result:
ok 1 number(s): "575284574"
Test #12:
score: 5
Accepted
time: 225ms
memory: 266108kb
input:
473458173541 864158404 220259603 529747800
output:
610487662
result:
ok 1 number(s): "610487662"
Test #13:
score: 5
Accepted
time: 206ms
memory: 266048kb
input:
459992983903 359742981 983942229 552405867
output:
81366483
result:
ok 1 number(s): "81366483"
Test #14:
score: 5
Accepted
time: 205ms
memory: 266180kb
input:
462331701308 665849375 563297194 141092054
output:
774987426
result:
ok 1 number(s): "774987426"
Test #15:
score: 5
Accepted
time: 834ms
memory: 266112kb
input:
9061635042931 746632077 302662913 559990819
output:
274721229
result:
ok 1 number(s): "274721229"
Test #16:
score: 5
Accepted
time: 987ms
memory: 266224kb
input:
9653325901537 559549569 638292572 474780356
output:
418906016
result:
ok 1 number(s): "418906016"
Test #17:
score: 5
Accepted
time: 930ms
memory: 266108kb
input:
9640271229478 619740479 644097590 907038757
output:
936646026
result:
ok 1 number(s): "936646026"
Test #18:
score: 5
Accepted
time: 974ms
memory: 265992kb
input:
9781711161203 988850684 154464719 995932763
output:
166841144
result:
ok 1 number(s): "166841144"
Test #19:
score: 5
Accepted
time: 901ms
memory: 266152kb
input:
9156325004698 915375188 316066096 217969045
output:
306877956
result:
ok 1 number(s): "306877956"
Test #20:
score: 5
Accepted
time: 939ms
memory: 266052kb
input:
9042535293051 906265264 156788435 622201740
output:
397975092
result:
ok 1 number(s): "397975092"