fork download
  1. #include<bits/stdc++.h>
  2. #define faster ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
  3. #define db double
  4. #define bo bool
  5. #define vo void
  6. #define ch char
  7. #define fl float
  8. #define ll long long
  9. #define ull unsigned long long
  10. #define str string
  11. #define re return
  12. #define all(x) (x).begin(),(x).end()
  13. using namespace std;
  14. //Đề Đại Học Sư Phạm Hà Nội
  15. vo bai1()
  16. {
  17. ll n,i,d=0;
  18. cin>>n;
  19. for(i=2;i*i<=n;i++)
  20. {
  21. if(n%i==0)
  22. {
  23. d=i;
  24. break;
  25. }
  26. }
  27. if(!d) cout<<n-1;
  28. else cout<<n-d;
  29. }
  30. vo bai2_bruteforce()
  31. {
  32. ll n,res=0,x,i;
  33. bo ok;
  34. str b;
  35. cin>>n>>b;
  36. bo check[10]={};
  37. for(ch c:b) check[c-'0']=1;
  38. for(i=1;i<=n;i++)
  39. {
  40. x=i;
  41. ok=1;
  42. while(x)
  43. {
  44. if(check[x%10])
  45. {
  46. ok=0;
  47. break;
  48. }
  49. x/=10;
  50. }
  51. if(ok) res++;
  52. }
  53. cout<<res;
  54. }
  55. str s;
  56. ll d[10],dp[20][2][2];
  57. ll TRY(ll i,ll t,ll l)
  58. {
  59. if(i==(ll)s.size()) re l?0:1;
  60. ll &r=dp[i][t][l],t1,l1,u=t?(s[i]-'0'):9;
  61. if(r!=-1) return r;
  62. r=0;
  63. for(ll j=0;j<=u;j++)
  64. {
  65. t1=t&&(j==u);
  66. l1=l&&(j==0);
  67. if(l1) r+=TRY(i+1,t1,1);
  68. else if(!d[j]) r+=TRY(i+1,t1,0);
  69. }
  70. re r;
  71. }
  72. vo bai2_deque()
  73. {
  74. ll n;
  75. str b;
  76. cin>>n>>b;
  77. for(ch c:b) d[c-'0']=1;
  78. s=to_string(n);
  79. memset(dp,-1,sizeof(dp));
  80. cout<<TRY(0,1,1);
  81. }
  82. vo bai2_dp()
  83. {
  84. ll n,m,i,j,k,v,l,q,z,p;
  85. str b;
  86. static ll f[20][2][2];
  87. str s;
  88. cin>>n>>b;
  89. s=to_string(n);
  90. m=s.size();
  91. bo check[10]={};
  92. for(ch c:b) check[c-'0']=1;
  93. f[0][1][1]=1;
  94. for(i=0;i<m;i++)
  95. {
  96. for(j=0;j<2;j++)
  97. for(k=0;k<2;k++)
  98. {
  99. v=f[i][j][k];
  100. if(!v) continue;
  101. p=j?(s[i]-'0'):9;
  102. for(l=0;l<=p;l++)
  103. {
  104. q=j&&(l==p);
  105. z=k&&(l==0);
  106. if(z) f[i+1][q][1] += v;
  107. else
  108. {
  109. if(check[l]) continue;
  110. f[i+1][q][0]+=v;
  111. }
  112. }
  113. }
  114. }
  115. cout<<f[m][0][0]+f[m][1][0];
  116. }
  117. vo bai3()
  118. {
  119. ll n,m,l=1,r,res,mid,i;
  120. bo ok;
  121. cin>>n>>m;
  122. r=n;
  123. res=n;
  124. vector<ll> a(n+1),b(n+1,0);
  125. for(i=1;i<=n;i++)
  126. {
  127. cin>>a[i];
  128. b[i]=b[i-1]+a[i];
  129. }
  130. while(l<=r)
  131. {
  132. ok=true;
  133. mid=(l+r)/2;
  134. for(i=mid;i<=n;i++)
  135. if(b[i]-b[i-mid]<m)
  136. {
  137. ok=false;
  138. break;
  139. }
  140. if(ok)
  141. {
  142. res=mid;
  143. r=mid-1;
  144. }
  145. else l=mid+1;
  146. }
  147. cout<<res;
  148. }
  149. vo bai4()
  150. {
  151. ll x,t,i,j,p=pow(2,9);
  152. vector<ll> v;
  153. v.push_back(0);
  154. for(i=1;i<p;i++)
  155. {
  156. x=0;
  157. for(j=0;j<9;j++)
  158. if(i&(1<<j)) x=x*10+(j+1);
  159. v.push_back(x);
  160. }
  161. sort(all(v));
  162. cin>>t;
  163. while(t--)
  164. {
  165. cin>>x;
  166. auto it=upper_bound(all(v),x);
  167. if(it==v.begin()) cout<<0<<"\n";
  168. else
  169. {
  170. it--;
  171. cout<<*it<<"\n";
  172. }
  173. }
  174. }
  175. int main()
  176. {
  177. faster
  178. // bai1();
  179. // bai2_bruteforce();
  180. // bai2_deque();
  181. // bai2_dp();
  182. // bai3();
  183. bai4();
  184. re 0;
  185. }
  186.  
  187.  
Success #stdin #stdout 0.01s 5288KB
stdin
Standard input is empty
stdout
123456789
123456789
123456789
123456789
123456789
123456789
123456789
123456789
123456789
123456789
123456789
123456789
123456789
123456789
123456789
123456789
123456789
123456789
123456789
123456789
123456789
123456789
123456789
123456789
123456789
123456789
123456789
123456789
123456789
123456789
123456789
123456789
123456789
123456789
123456789
123456789
123456789
123456789
123456789
123456789
123456789
123456789
123456789
123456789
123456789
123456789
123456789
123456789
123456789
123456789
123456789
123456789
123456789
123456789
123456789
123456789
123456789
123456789
123456789
123456789
123456789
123456789
123456789
123456789
123456789
123456789
123456789
123456789
123456789
123456789
123456789
123456789
123456789
123456789
123456789
123456789
123456789
123456789
123456789
123456789
123456789
123456789
123456789
123456789
123456789
123456789
123456789
123456789
123456789
123456789
123456789
123456789
123456789
123456789
123456789
123456789
123456789
123456789
123456789
123456789
123456789
123456789
123456789
123456789
123456789
123456789
123456789
123456789
123456789
123456789
123456789
123456789
123456789
123456789
123456789
123456789
123456789
123456789
123456789
123456789
123456789
123456789
123456789
123456789
123456789
123456789
123456789
123456789
123456789
123456789
123456789
123456789
123456789
123456789
123456789
123456789
123456789
123456789
123456789
123456789
123456789
123456789
123456789
123456789
123456789
123456789
123456789
123456789
123456789
123456789
123456789
123456789
123456789
123456789
123456789
123456789
123456789
123456789
123456789
123456789
123456789
123456789
123456789
123456789
123456789
123456789
123456789
123456789
123456789
123456789
123456789
123456789
123456789
123456789
123456789
123456789
123456789
123456789
123456789
123456789
123456789
123456789
123456789
123456789
123456789
123456789
123456789
123456789
123456789
123456789
123456789
123456789
123456789
123456789
123456789
123456789
123456789
123456789
123456789
123456789
123456789
123456789
123456789
123456789
123456789
123456789
123456789
123456789
123456789
123456789
123456789
123456789
123456789
123456789
123456789
123456789
123456789
123456789
123456789
123456789
123456789
123456789
123456789
123456789
123456789
123456789
123456789
123456789
123456789
123456789
123456789
123456789
123456789
123456789
123456789
123456789
123456789
123456789
123456789
123456789
123456789
123456789
123456789
123456789
123456789
123456789
123456789
123456789
123456789
123456789
123456789
123456789
123456789
123456789
123456789
123456789
123456789
123456789
123456789
123456789
123456789
123456789
123456789
123456789
123456789
123456789
123456789
123456789
123456789
123456789
123456789
123456789
123456789
123456789
123456789
123456789
123456789
123456789
123456789
123456789
123456789
123456789
123456789
123456789
123456789
123456789
123456789
123456789
123456789
123456789
123456789
123456789
123456789
123456789
123456789
123456789
123456789
123456789
123456789
123456789
123456789
123456789
123456789
123456789
123456789
123456789
123456789
123456789
123456789
123456789
123456789
123456789
123456789
123456789
123456789
123456789
123456789
123456789
123456789
123456789
123456789
123456789
123456789
123456789
123456789
123456789
123456789
123456789
123456789
123456789
123456789
123456789
123456789
123456789
123456789
123456789
123456789
123456789
123456789
123456789
123456789
123456789
123456789
123456789
123456789
123456789
123456789
123456789
123456789
123456789
123456789
123456789
123456789
123456789
123456789
123456789
123456789
123456789
123456789
123456789
123456789
123456789
123456789
123456789
123456789
123456789
123456789
123456789
123456789
123456789
123456789
123456789
123456789
123456789
123456789
123456789
123456789
123456789
123456789
123456789
123456789
123456789
123456789
123456789
123456789
123456789
123456789
123456789
123456789
123456789
123456789
123456789
123456789
123456789
123456789
123456789
123456789
123456789
123456789
123456789
123456789
123456789
123456789
123456789
123456789
123456789
123456789
123456789
123456789
123456789
123456789
123456789
123456789
123456789
123456789
123456789
123456789
123456789
123456789
123456789
123456789
123456789
123456789
123456789
123456789
123456789
123456789
123456789
123456789
123456789
123456789
123456789
123456789
123456789
123456789
123456789
123456789
123456789
123456789
123456789
123456789
123456789
123456789
123456789
123456789
123456789
123456789
123456789
123456789
123456789
123456789
123456789
123456789
123456789
123456789
123456789
123456789
123456789
123456789
123456789
123456789
123456789
123456789
123456789
123456789
123456789
123456789
123456789
123456789
123456789
123456789
123456789
123456789
123456789
123456789
123456789
123456789
123456789
123456789
123456789
123456789
123456789
123456789
123456789
123456789
123456789
123456789
123456789
123456789
123456789
123456789
123456789
123456789
123456789
123456789
123456789
123456789
123456789
123456789
123456789
123456789
123456789
123456789
123456789
123456789
123456789
123456789
123456789
123456789
123456789
123456789
123456789
123456789
123456789
123456789
123456789
123456789
123456789
123456789
123456789
123456789
123456789
123456789
123456789
123456789
123456789
123456789
123456789
123456789
123456789
123456789
123456789
123456789
123456789
123456789
123456789
123456789
123456789
123456789
123456789