QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#605677#9107. Zayin and Countjiangzhihui#AC ✓43ms3664kbC++143.7kb2024-10-02 18:33:072024-10-02 18:33:14

Judging History

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

  • [2024-10-02 18:33:14]
  • 评测
  • 测评结果:AC
  • 用时:43ms
  • 内存:3664kb
  • [2024-10-02 18:33:07]
  • 提交

answer

#include <iostream>
#include <cstdio>
#include <algorithm>
#include <unordered_map>
#include <vector>
#include <map>
#include <list>
#include <queue>
#include <cstring>
#include <cstdlib>
#include <ctime>
#include <cmath>
#include <stack>
#include <set>
#include <bitset>
#include <deque>
#include <bits/stdc++.h>
using namespace std ;
#define ios ios::sync_with_stdio(false) , cin.tie(0)
#define x first
#define y second
#define pb push_back
#define ls rt << 1
#define rs rt << 1 | 1
typedef long long ll ;
const double esp = 1e-6 , pi = acos(-1) ;
typedef pair<int , int> PII ;
const int N = 1e6 + 10 , INF = 0x3f3f3f3f , mod = 1e9 + 7;
int a[2][11] , c[100] , cnt ;
__int128 dp[1100][2] ;
void print(__int128 x) {
  vector<int> v ;
  while(x) v.push_back(x % 10) , x /= 10 ;
  if(v.size() == 0) v.push_back(0) ;
  reverse(v.begin() , v.end()) ;
  for(auto x : v)
   printf("%d" , x) ;
  printf("\n") ;
}
__int128 dfs(int u  , int flag , int limit , int t) {
    if(u == 0)  return flag == 0 ;
    if(!limit && dp[u][flag] != -1) return dp[u][flag] ;
    int end = limit ? c[u] : 9 ;
    __int128 ans = 0 ;
    for(int i = 0 ;i <= end; i ++ )
        if(a[t][i])   ans += dfs(u - 1 , flag && i == 0 , limit && end == i , t) ;
    if(!limit) dp[u][flag] = ans ;
    return ans ;
}
__int128 solve(string x , int t) {
    cnt = 0 ;
    for(int i = x.size() - 1; i >= 0 ;i -- ) c[++ cnt] = x[i] - '0' ;
    return dfs(cnt , 1 , 1 , t) + a[t][0]  ;
}
__int128 in() {
    __int128 x = 0 ;
    char ch = getchar() ;
    while(ch < '0' || ch > '9') ch = getchar() ;
    while(ch >= '0' && ch <= '9') x = x * 10 + ch - 48 , ch = getchar() ;
    return x ;
}
__int128 qmi(__int128 a , __int128 b) {
  __int128 res = 1 ;
  while(b) {
    if(b & 1) res = res * a ;
    a = a * a ;
    b >>= 1 ;
  }
  return res ;
}
__int128 t[N] ;
int work()
{
  __int128 q = 0 , cnt1 = 0 ;
  for(int i = 0; i < 10 ;i ++ ) cin >> a[0][i] , cnt1 += a[0][i] ;
  for(int i = 0 ;i < 10 ;i ++ ) cin >> a[1][i] , q += a[1][i] ;
  assert(q>0);
  memset(dp , -1 , sizeof dp) ;
  string x ;
  cin >> x ;
 
  __int128 p = solve(x , 0)  ;
  __int128 d = cnt1 ;
  if(a[0][0] == 0) {
      for(int i = 1; i < cnt ;i ++ )
       p += d , d *= cnt1 ;
  }
 
  string ans = "" ;
 
  t[0] = 1 ;
  __int128 res = 0 ;
  int flag = 0 ;
 
  if(a[1][0]) p -- ;
 
  if(p == 0) {
      for(int j = 0 ;j < 10 ;j ++ )
        if(a[1][j]) {
            cout << j << endl ;
            return 0 ;
        }
  }
  for(int i = 1; ;i ++ ) {
      t[i] = t[i - 1] * q ;
      for(int j = 1 ; j < 10 ;j ++ ) {
          if(a[1][j]) {
              if(res + t[i - 1] >= p) {
                  p -= res ;
                  ans += j + '0' ;
                  flag =  i ;
                  break ;
 
              }
              res += t[i - 1] ;
          }
      }
 
      if(flag) break ;
  }
  for(int i = flag - 1; i >= 1; i -- ) {
      int ok = 0 , tt = -1 ;
      __int128 res = 0 ;
      for(int j = 0 ;j < 10 ;j ++ ) {
          if(a[1][j]) {
              tt = j ;
              if(res + t[i - 1] >= p) {
                  p -= res ;
                  ans += j + '0' ;
                  ok = 1;
                  break ;
              }
              res += t[i - 1] ;
          }
      }
      if(!ok && tt != -1) ans += tt + '0' , p -= (__int128)q * t[i - 1] ;
  }
  cout << ans   << "\n" ;
  return 0 ;
}
int main()
{
  //   freopen("C://Users//spnooyseed//Desktop//in.txt" , "r" , stdin) ;
  //   freopen("C://Users//spnooyseed//Desktop//out.txt" , "w" , stdout) ;
  int n ;
  ios ;
  cin >> n ;
  while(n --)
  work() ;
  return 0 ;
}
/*
*/

詳細信息

Test #1:

score: 100
Accepted
time: 43ms
memory: 3664kb

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