QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#608494#4056. 进制转换JWRuixi100 ✓1404ms134796kbC++202.2kb2024-10-03 22:13:492024-10-03 22:13:50

Judging History

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

  • [2024-10-03 22:13:50]
  • 评测
  • 测评结果:100
  • 用时:1404ms
  • 内存:134796kb
  • [2024-10-03 22:13:49]
  • 提交

answer

#ifdef LOCAL
#include "stdafx.h"
#else
#include <bits/stdc++.h>
#define IL inline
#define LL long long
#define eb emplace_back
#define sz(v) ((int) (v).size())
#define L(i, j, k) for (int i = (j); i <= (k); ++i)
#define R(i, j, k) for (int i = (j); i >= (k); --i)
#define FIO(FILE) freopen(FILE".in", "r", stdin), freopen(FILE".out", "w", stdout)
using namespace std;

using vi = vector<int>;
#endif

constexpr int LG = 28;
constexpr int P = 998244353;
LL n;
int x, y, z;

IL constexpr int qpow (int b, int k = P - 2) {
  int r = 1;
  for (; k; k >>= 1, b = (LL)b * b % P) if (k & 1) r = (LL)r * b % P;
  return r;
}

LL p3[LG + 3], sum[LG / 2 + 3];
int l[LG + 3], bt[LG + 3], ppc[1 << 10], pwx[LG + 3][3], pwy[1 << 10], pwz[3];

void init () {
  p3[0] = 1;
  L (i, 1, LG) {
    p3[i] = p3[i - 1] * 3;
  }
  L (i, 0, LG) {
    while (p3[i] >> l[i]) {
      ++l[i];
    }
  }
  L (i, 1, LG / 2) {
    sum[i] = sum[i - 1] + (1 << l[i]);
  }
  pwy[0] = 1;
  L (i, 1, (1 << 10) - 1) {
    ppc[i] = ppc[i >> 1] + i % 2;
    pwy[i] = (LL)pwy[i - 1] * y % P;
  }
  pwz[0] = 1, pwz[1] = z, pwz[2] = (LL)z * z % P;
  L (i, 0, LG) {
    int X = qpow(x, p3[i] % (P - 1));
    pwx[i][0] = 1, pwx[i][1] = X, pwx[i][2] = (LL)X * X % P;
  }
  L (i, 0, LG) {
    bt[i] = n % 3;
    n /= 3;
  }
}

int f[1 << 24][2];

int dfs (int d, LL cur, bool c, bool lim) {
  if (d == -1) {
    return c ? 0 : pwy[ppc[cur]];
  }
  if (!lim && d < LG / 2 && ~f[cur + sum[d]][c]) {
    return f[cur + sum[d]][c];
  }
  int s = 0;
  L (i, 0, lim ? bt[d] : 2) {
    L (nc, 0, 1) {
      LL ncur = cur + ((LL)nc << l[d]) + p3[d] * i;
      if ((ncur >> l[d + 1]) != c) {
        continue;
      }
      ncur &= (1LL << l[d + 1]) - 1;
      int X = pwx[d][i], Y = pwy[ppc[ncur >> l[d]]], Z = pwz[i];
      s = (s + (LL)X * Y % P * Z % P * dfs(d - 1, ncur & ((1LL << l[d]) - 1), nc, lim & (i == bt[d]))) % P;
    }
  }
  if (!lim && d < LG / 2) {
    f[cur + sum[d]][c] = s;
  }
  return s;
}

int main () {
  ios::sync_with_stdio(0), cin.tie(0);
  cin >> n >> x >> y >> z;
  init();
  memset(f, -1, sizeof(f));
  cout << (P - 1 + dfs(LG - 1, 0, false, true)) % P << '\n';
}
// I love WHQ!

詳細信息


Pretests


Final Tests

Test #1:

score: 5
Accepted
time: 7ms
memory: 134664kb

input:

9134097 778012792 263448561 839843856

output:

887680205

result:

ok 1 number(s): "887680205"

Test #2:

score: 5
Accepted
time: 0ms
memory: 134732kb

input:

9896386 2948513 263418583 271155379

output:

853292631

result:

ok 1 number(s): "853292631"

Test #3:

score: 5
Accepted
time: 0ms
memory: 134716kb

input:

9150910 827328107 842171962 39947937

output:

534921610

result:

ok 1 number(s): "534921610"

Test #4:

score: 5
Accepted
time: 1213ms
memory: 134796kb

input:

9586674634211 1 1 58301262

output:

13306748

result:

ok 1 number(s): "13306748"

Test #5:

score: 5
Accepted
time: 1014ms
memory: 134664kb

input:

9774917720998 1 1 609549524

output:

825025220

result:

ok 1 number(s): "825025220"

Test #6:

score: 5
Accepted
time: 1058ms
memory: 134676kb

input:

9765239207265 422503033 1 719749187

output:

993518920

result:

ok 1 number(s): "993518920"

Test #7:

score: 5
Accepted
time: 1002ms
memory: 134724kb

input:

9732354736444 277693641 1 501293609

output:

77844778

result:

ok 1 number(s): "77844778"

Test #8:

score: 5
Accepted
time: 32ms
memory: 134664kb

input:

9004409828 377918953 449219487 26422407

output:

110868569

result:

ok 1 number(s): "110868569"

Test #9:

score: 5
Accepted
time: 27ms
memory: 134652kb

input:

9579878149 820453354 218842704 133154415

output:

727248713

result:

ok 1 number(s): "727248713"

Test #10:

score: 5
Accepted
time: 23ms
memory: 134732kb

input:

9475807443 305433821 391589421 170059051

output:

372839725

result:

ok 1 number(s): "372839725"

Test #11:

score: 5
Accepted
time: 286ms
memory: 134728kb

input:

484758270277 372146623 410538257 35340632

output:

575284574

result:

ok 1 number(s): "575284574"

Test #12:

score: 5
Accepted
time: 272ms
memory: 134676kb

input:

473458173541 864158404 220259603 529747800

output:

610487662

result:

ok 1 number(s): "610487662"

Test #13:

score: 5
Accepted
time: 266ms
memory: 134796kb

input:

459992983903 359742981 983942229 552405867

output:

81366483

result:

ok 1 number(s): "81366483"

Test #14:

score: 5
Accepted
time: 279ms
memory: 134676kb

input:

462331701308 665849375 563297194 141092054

output:

774987426

result:

ok 1 number(s): "774987426"

Test #15:

score: 5
Accepted
time: 1008ms
memory: 134668kb

input:

9061635042931 746632077 302662913 559990819

output:

274721229

result:

ok 1 number(s): "274721229"

Test #16:

score: 5
Accepted
time: 1301ms
memory: 134792kb

input:

9653325901537 559549569 638292572 474780356

output:

418906016

result:

ok 1 number(s): "418906016"

Test #17:

score: 5
Accepted
time: 1219ms
memory: 134732kb

input:

9640271229478 619740479 644097590 907038757

output:

936646026

result:

ok 1 number(s): "936646026"

Test #18:

score: 5
Accepted
time: 1404ms
memory: 134792kb

input:

9781711161203 988850684 154464719 995932763

output:

166841144

result:

ok 1 number(s): "166841144"

Test #19:

score: 5
Accepted
time: 1125ms
memory: 134792kb

input:

9156325004698 915375188 316066096 217969045

output:

306877956

result:

ok 1 number(s): "306877956"

Test #20:

score: 5
Accepted
time: 1056ms
memory: 134744kb

input:

9042535293051 906265264 156788435 622201740

output:

397975092

result:

ok 1 number(s): "397975092"