QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#605640 | #9107. Zayin and Count | jiangzhihui# | RE | 0ms | 0kb | C++14 | 1.6kb | 2024-10-02 18:16:06 | 2024-10-02 18:16:06 |
answer
#include <bits/stdc++.h>
using namespace std;
void solve() {
vector<int> a(10, -1);
vector<int> b;
for (int i = 0, cur = 0; i < 10; i++) {
int x;
cin >> x;
if (x == 1) a[i] = ++cur;
}
for (int i = 0, cur = 0; i < 10; i++) {
int x;
cin >> x;
if (x == 1) b.push_back(i);
}
unsigned long long x;
cin >> x;
auto get = [&](unsigned long long x) {
vector<pair<int, unsigned long long>> v;
unsigned long long cnt = 0;
for (auto u : a)
if (u != -1) cnt += 1;
unsigned long long cur = 1;
while (x > 0) v.push_back({x % 10, cur}), x /= 10, cur *= cnt;
unsigned long long ans = 1;
int cnt2 = 0;
while (!v.empty()) {
cnt2++;
assert(cnt <= 1e6);
auto [c, cnt] = v.back();
v.pop_back();
ans += (a[c] - 1) * cnt;
}
return ans;
};
unsigned long long t = get(x);
int num = 1;
// cnt = 3
// [1 , cnt ^ num] [1 , 3]
// [cnt ^ num + 1 , cnt ^ (num + 1)] [4 , 9]
// [cnt ^ (num + 1) + 1 , cnt ^ (num + 2)] [10 , 27]
unsigned long long cnt = b.size() ;
__int128 cur = 1;
vector<__int128> p;
int cnt2 = 0;
while (cur < t) {
cnt2++;
// assert(cnt2 <= 1e6);
// assert(cur >= 0) ;
assert(cnt > 0) ;
p.push_back(cur);
if (t <= (__int128)(cur)*cnt) break;
cur *= cnt;
num += 1;
}
t -= 1;
for (int i = num; i >= 1; i--) {
cout << b[t / p[i - 1]];
t %= p[i - 1];
}
cout << '\n';
}
int main() {
std::ios::sync_with_stdio(false), cin.tie(0);
int T;
cin >> T;
while (T--) solve();
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 ...