QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#605585#9107. Zayin and Countjiangzhihui#TL 0ms0kbC++141.8kb2024-10-02 18:04:162024-10-02 18:04:16

Judging History

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

  • [2024-10-02 18:04:16]
  • 评测
  • 测评结果:TL
  • 用时:0ms
  • 内存:0kb
  • [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 ...

output:


result: