QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#504667#9107. Zayin and CountPlentyOfPenalty#AC ✓12ms3608kbC++201.8kb2024-08-04 14:38:122024-08-04 14:38:12

Judging History

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

  • [2024-08-04 14:38:12]
  • 评测
  • 测评结果:AC
  • 用时:12ms
  • 内存:3608kb
  • [2024-08-04 14:38:12]
  • 提交

answer

#include <bits/stdc++.h>
#define all(x) begin(x), end(x)
#define rep(i, l, r) for (int i = (l), i##end = (r); i <= i##end; ++i)
#define per(i, l, r) for (int i = (l), i##end = (r); i >= i##end; --i)
#ifdef memset0
#define log(...) fprintf(stderr, __VA_ARGS__)
#else
#define log(...) (void(0))
#define endl '\n'
#endif
using namespace std;
using ll = long long;
using lf = long double;
using ull = unsigned long long;
using LL = __int128;
const int L = 70;
int T, s1[15], rk1[15], sz1, s2[15], a2[15], sz2;
string str;
LL Enc(int *s, int *a, int n, string t) {
  LL ret = 0;
  if (s[0]) {
    LL pw = 1;
    for (int i = t.size() - 1; i >= 0; --i) ret += pw * a[t[i] - '0'], pw *= n;
  } else {
    LL pw = 1;
    for (int i = 1; i < t.size(); ++i) pw *= n, ret += pw;
    // cerr << "RET=" << (ull)ret << "\n";
    pw = 1;
    for (int i = t.size() - 1; i >= 0; --i) ret += pw * a[t[i] - '0'], pw *= n;
  }
  // cerr << "RET=" << (ull)ret << "\n";
  return ret;
}
int tmp[L + 10], sz;
string Dec(int *s, int *a, int n, LL rk) {
  if (s[0]) {
    while (rk) tmp[++sz] = rk % n, rk /= n;
  } else {
    sz = 1;
    LL pw = n;
    while (rk > pw) rk -= pw, ++sz, pw *= n;
    for (int i = 1; i <= sz; ++i) tmp[i] = rk % n, rk /= n;
  }
  string ret = "";
  for (int i = sz; i >= 1; --i) ret += a[tmp[i]] + '0';
  return ret;
}
int main() {
#ifdef memset0
  freopen("G.in", "r", stdin);
#endif
  cin.tie(0)->sync_with_stdio(0);
  cin >> T;
  while (T--) {
    sz = 0;
    sz1 = sz2 = 0;
    for (int i = 0; i <= 9; ++i) {
      cin >> s1[i];
      if (s1[i]) rk1[i] = (sz1++);
    }
    for (int i = 0; i <= 9; ++i) {
      cin >> s2[i];
      if (s2[i]) a2[sz2++] = i;
    }
    cin >> str;
    cout << Dec(s2, a2, sz2, Enc(s1, rk1, sz1, str)) << "\n";
  }
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 12ms
memory: 3608kb

input:

10000
1 0 0 0 1 1 0 0 0 1
0 0 1 0 1 1 1 1 0 0
950595954440050004054505054050
1 0 0 0 1 1 1 1 0 0
1 1 1 0 1 0 0 0 1 1
45467007076660767550460064
1 1 1 1 0 0 0 1 0 0
1 1 0 1 1 0 1 0 0 1
23373171320213300170200722
0 0 0 0 1 1 1 0 1 0
0 0 1 0 0 1 0 1 1 1
558565664666565565558468668484
1 1 0 0 1 0 1 0 1 ...

output:

52755244567262766742575722
41990991999414091249949
101364364636933104003903
57558888789255872922852552
757222758857875785288225787822
761161760076076167101117776167
56666586555668686566656586856566686658
15611661611611111511116116661611616155
505885888775005550558080707878
3912911219633669993999199
...

result:

ok 10000 lines