QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#605585 | #9107. Zayin and Count | jiangzhihui# | TL | 0ms | 0kb | C++14 | 1.8kb | 2024-10-02 18:04:16 | 2024-10-02 18:04:16 |
answer
#include <bits/stdc++.h>
using namespace std ;
void solve()
{
vector<int> a(10 , -1) ;
vector<int> b(10 , -1) ;
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[cur ++] = 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 ;
while(!v.empty())
{
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 = 0 ;
for(auto u : b) if(u != -1) cnt += 1 ;
unsigned long long cur = 1 ;
vector<unsigned long long> p ;
while(cur < t)
{
p.push_back(cur) ;
if(t <= (__int128)(cur) * cnt) break ;
cur *= cnt ;
num += 1 ;
}
t -= 1 ;
for(int i = num ; i >= 1 ; i --)
{
assert(p[i - 1] > 0) ;
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 ;
}
詳細信息
Test #1:
score: 0
Time Limit Exceeded
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 ...