QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#374702 | #5273. Hidden Digits | zhouhuanyi | RE | 435ms | 23764kb | C++14 | 3.4kb | 2024-04-02 17:16:09 | 2024-04-02 17:16:09 |
Judging History
answer
#include<iostream>
#include<cstdio>
#include<algorithm>
#define N 10
#define M 1000000
#define K 6
using namespace std;
const long long inf=(long long)(1e12);
const long long INF=(long long)(1e18);
int read()
{
char c=0;
int sum=0;
while (c<'0'||c>'9') c=getchar();
while ('0'<=c&&c<='9') sum=sum*10+c-'0',c=getchar();
return sum;
}
int T,n,len,ds[M+1],tong[N+1],length,sz[M+1],pw10[K+1],d[N+1],dp[M+1][K+1],dp2[M+1][K+1];
long long F[1<<N],G[1<<N][1<<N],ans;
int calc(int len,int l,int r,int x)
{
if (l==0&&r==pw10[len]-1) return dp2[x][len];
if (l/pw10[len-1]==r/pw10[len-1]) return calc(len-1,l%pw10[len-1],r%pw10[len-1],x)&(((1<<10)-1)^(1<<(l/pw10[len-1])));
else
{
int sl=l/pw10[len-1],sr=r/pw10[len-1],res=0;
for (int i=sl;i<=sr;++i)
{
if (i==sl) res|=(calc(len-1,l-i*pw10[len-1],pw10[len-1]-1,x)&(((1<<10)-1)^(1<<i))),x+=((i+1)*pw10[len-1]-l);
else if (i==sr) res|=(calc(len-1,0,r-i*pw10[len-1],x)&(((1<<10)-1)^(1<<i))),x+=(r-i*pw10[len-1]+1);
else res|=(calc(len-1,0,pw10[len-1]-1,x)&(((1<<10)-1)^(1<<i))),x+=pw10[len-1];
}
return res;
}
}
bool query(int l,int r)
{
if (sz[l]==sz[r]) return !calc(sz[l],l,r,0);
else
{
int x=0;
bool op=1;
for (int i=sz[l];i<=sz[r];++i)
{
if (i==sz[l]) op&=(!calc(i,l,pw10[i]-1,x)),x+=pw10[i]-l;
else if (i==sz[r]) op&=(!calc(i,pw10[i-1],r,x)),x+=r-pw10[i-1]+1;
else op&=(!calc(i,pw10[i-1],pw10[i]-1,x)),x+=pw10[i]-pw10[i-1];
}
return op;
}
}
int main()
{
char c;
int d;
long long res;
for (int i=1;i<=M;++i) sz[i]=sz[i/10]+1;
pw10[0]=1;
for (int i=1;i<=6;++i) pw10[i]=pw10[i-1]*10;
for (int i=0;i<(1<<10);++i) F[i]=inf;
for (int i=0;i<(1<<10);++i)
for (int j=0;j<(1<<10);++j)
G[i][j]=inf;
for (int i=0;i<(1<<10);++i)
if (i!=1)
{
length=0;
for (int j=0;j<=9;++j)
if ((i>>j)&1)
tong[++length]=j;
sort(tong+1,tong+length+1);
if (!tong[1]) swap(tong[1],tong[2]);
res=0;
for (int j=1;j<=length;++j) res=res*10+tong[j];
F[i]=res;
for (int j=0;j<=8;++j) G[i|((i||j)?(1<<j):0)][i|(1<<(j+1))]=min(G[i|((i||j)?(1<<j):0)][i|(1<<(j+1))],res*10+j);
for (int j=0;j<=8;++j) G[i|((i||j)?(1<<j):0)|(1<<9)][i|(1<<(j+1))|(1<<0)]=min(G[i|((i||j)?(1<<j):0)|(1<<9)][i|(1<<(j+1))|(1<<0)],res*100+j*10+9);
}
F[1]=F[3];
for (int i=(1<<10)-1;i>=0;--i)
for (int j=(1<<10)-1;j>=0;--j)
for (int k=0;k<=9;++k)
{
if (!((i>>k)&1)) G[i][j]=min(G[i][j],G[i|(1<<k)][j]);
if (!((j>>k)&1)) G[i][j]=min(G[i][j],G[i][j|(1<<k)]);
}
T=read();
while (T--)
{
n=read(),ans=INF,len=sz[n-1];
for (int i=0;i<n;++i) cin>>c,ds[i]=c-'0';
for (int i=0;i<n;++i) dp[i][0]=dp2[i][0]=1<<ds[i];
for (int i=0;i<n;++i)
for (int j=1;j<=len;++j)
{
dp[i][j]=0;
for (int k=9;k>=0;--k)
if (i>=(9-k)*pw10[j-1])
dp[i][j]|=dp[i-(9-k)*pw10[j-1]][j-1]&(((1<<10)-1)^(1<<k));
}
for (int i=n-1;i>=0;--i)
for (int j=1;j<=len;++j)
{
dp2[i][j]=0;
for (int k=0;k<=9;++k)
if (i+k*pw10[j-1]<=n-1)
dp2[i][j]|=dp2[i+k*pw10[j-1]][j-1]&(((1<<10)-1)^(1<<k));
}
for (int i=0;i<=n-2;++i)
if (G[dp[i][len]][dp2[i+1][len]]!=inf)
ans=min(ans,max(G[dp[i][len]][dp2[i+1][len]],1ll)*pw10[len]+pw10[len]-i-1);
for (int i=1;i<pw10[len];++i)
if (query(i,i+n-1))
ans=min(ans,(long long)(i));
for (int i=0;i+n-1<pw10[len];++i) d=calc(len,i,i+n-1,0),ans=min(ans,max(F[d],1ll)*pw10[len]+i);
printf("%lld\n",ans);
}
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 41ms
memory: 19260kb
input:
6 5 12345 5 01234 3 239 9 998244353 10 1000000007 20 18446744073709551616
output:
1 10 92 45296 701 10367486
result:
ok 6 numbers
Test #2:
score: 0
Accepted
time: 55ms
memory: 20856kb
input:
100 164 69890100410019112111171102121162123121316739414441411451215511811111411666712771777701218561891113156991212202620022134261820122426722022222372222224564295125452559 878 211333331123456484555141518901166516110113417777018311678801199197912200406722012211122121234222892222353322012424228402555...
output:
96 132 439 122 616 93 641 63 683 747 986 754 110 517 415 507 750 110 284 53 843 913 96 495 796 980 350 15 883 976 8 969 432 535 763 951 3 275 936 117 538 382 375 209 615 47 949 624 959 630 824 484 581 761 167 163 938 223 719 284 485 480 430 162 841 459 373 557 794 377 599 809 60 971 414 663 583 894 ...
result:
ok 100 numbers
Test #3:
score: 0
Accepted
time: 140ms
memory: 20156kb
input:
100000 8 75332714 10 2593248958 7 2570951 3 900 8 52496150 10 7106318056 4 2000 6 528421 7 8428056 8 14800524 2 85 2 49 2 35 2 04 1 3 9 242194783 2 42 2 78 10 4537960080 3 495 9 955414779 6 834990 6 751167 7 6979405 4 7719 4 2423 6 790165 6 782986 5 26088 4 5677 6 300911 1 0 5 35315 3 142 4 5462 2 3...
output:
12734 235889 2505 99 102592 103677 102 2456 4080 10446 58 48 34 40 3 123491 24 7 36794 48 45967 8092 1572 6495 176 233 5678 26876 2085 75 306 10 1349 123 459 13 127855 1 10739 39 20454 5906 2 13594 460 13470 564 60 124677 2575 250 103468 30 37909 106 2889 1052 36 393 8 1045 10458 4 36 687 9 5788 309...
result:
ok 100000 numbers
Test #4:
score: 0
Accepted
time: 185ms
memory: 20640kb
input:
10000 8 64551991 94 8908239748745103390617336217621091342925136242069726255551754986003838521538075967122990035597 3 366 50 17261403553042681301592228034099763466285593197925 70 6512752606043010515642674438133034556237470965017382180546251858663955 4 1575 14 13738597354878 1 1 44 1271614313865680851...
output:
14586 102345678888 63 10234567869 10234567826 155 578391 1 10234567869 14567927 102345678864 1023688 306717 1023569782 102345678876 102345678864 102345678889 30494 102345678879 5859 10245678898 102345678878 102345678886 102345678882 1236493 102345677 102345678885 102345678878 1235 102345677956 15792...
result:
ok 10000 numbers
Test #5:
score: 0
Accepted
time: 256ms
memory: 19576kb
input:
1000 13 5139990076849 853 4320188783532862415927414556906207860422279569150209288463017070018921778969634469686643059298004525826712396039523006465135975372248365253980074496695105274277279555949598566712425606778209885682018426390381825062981824931051187739167659882723128083674753598607225635089461...
output:
10347958 1023456788870 102345678856 1023456788862 102345678884 1023456788826 1023456788857 1023456788857 1023456788836 1023456788875 1023456788885 102345678882 102345768 10234567878 102345678882 1023456788887 1023456788875 1023456788888 1023456788785 1023456788889 1023456788881 1023456788877 1023456...
result:
ok 1000 numbers
Test #6:
score: 0
Accepted
time: 339ms
memory: 20876kb
input:
100 2473 035240593204479336022647750779505988885071239040880354860105778384171514626457911845962356354493984192931068637984357892651860102331372794324945457430024023431825705858326659002759397047783077893150415556336882933044290118518194229492600555429709728181287147299044130734520980585135713147185...
output:
10234567888882 1023456788876 10234567888889 10234567888866 10234567888883 10234567888846 10234567888886 1234567889966 10234567888872 10234567888876 10234567888850 10234567888879 10234567888862 10234567888871 1023456788877 10234567888864 10234567888872 1234567808889 10234567888889 10234567888872 1023...
result:
ok 100 numbers
Test #7:
score: 0
Accepted
time: 435ms
memory: 23764kb
input:
10 43260 373039883067573264249378597706968049120299430099195084579424045895063448703767926565059241137222919444838185356362113856750039606708109040349124652801223312921209448604305299772630917872017561117475367667875126578670674876143893646726082305715769870366685965942121692036654693410322307072763...
output:
102345678888874 102345678888862 102345678888879 102345678888886 102345678888884 102345678888875 102345678888889 102345678888882 102345678888879 102345678888888
result:
ok 10 numbers
Test #8:
score: -100
Runtime Error
input:
1 1000000 54278434494582612477754229700028744890387566738908723965218097889651614007695274259463605843854511093706263884453468838905463774153627559232463324132806122306278886180497036026670553026122641423380003735206971396360375524422896335908112776274550364000216693859506800272613291792797966846872...