QOJ.ac
QOJ
The 2nd Universal Cup Finals is coming! Check out our event page, schedule, and competition rules!
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#569884 | #9107. Zayin and Count | SGColin# | RE | 0ms | 0kb | C++17 | 1.6kb | 2024-09-17 11:48:45 | 2024-09-17 11:48:47 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
inline ll rd() {
ll x = 0;
bool f = 0;
char c = getchar();
for (; !isdigit(c); c = getchar()) f |= (c == '-');
for (; isdigit(c); c = getchar()) x = x * 10 + (c ^ 48);
return f ? -x : x;
}
#define eb emplace_back
#define all(s) (s).begin(), (s).end()
#define rep(i, a, b) for (int i = (a); i <= (b); ++i)
#define per(i, a, b) for (int i = (a); i >= (b); --i)
const int N = 100007;
char s[N];
ull fpow(ull x, int t) {
ull res = 1;
for (; t; t >>= 1, x = x * x)
if (t & 1) res = res * x;
return res;
}
void work() {
vector<int> A, B;
rep(i, 0, 9) {int w = rd(); if (w) A.eb(i);}
rep(i, 0, 9) {int w = rd(); if (w) B.eb(i);}
scanf("%s", s + 1);
int n = strlen(s + 1);
auto getv = [&](vector<int> &s, int w) {
return lower_bound(all(s), w) - s.begin() + 1;
};
ull tot = 0;
if (A[0] != 0) {
int w = getv(A, s[1] - '0');
rep(i, 1, n - 1) tot += fpow(A.size(), i);
}
rep(i, 1, n) {
int w = getv(A, s[i] - '0');
tot += (w - 1) * fpow(A.size(), n - i);
}
++tot;
vector<int> ans;
if (B[0] == 0) {
--tot;
if (tot == 0) ans.eb(B[0]);
while (tot) {
ans.eb(B[tot % B.size()]);
tot /= B.size();
}
reverse(all(ans));
} else {
int pos = 1;
while (true) {
ull cntl = fpow(B.size(), pos);
if (tot > cntl) tot -= cntl;
else break;
++pos;
}
per(i, pos, 1) {
ull cntl = fpow(B.size(), i);
ans.eb(B[(tot - 1) / cntl]);
tot %= cntl;
}
}
for (auto x : ans) printf("%d", x); puts("");
}
int main() {
per(t, rd(), 1) work();
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 0
Runtime Error
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 ...