QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#374699 | #5273. Hidden Digits | zhouhuanyi | WA | 155ms | 19932kb | C++14 | 3.4kb | 2024-04-02 17:13:52 | 2024-04-02 17:13:52 |
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);
}
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;
}
詳細信息
Test #1:
score: 100
Accepted
time: 35ms
memory: 19932kb
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: 56ms
memory: 19812kb
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: -100
Wrong Answer
time: 155ms
memory: 19860kb
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 200 2456 4080 10446 58 48 34 40 3 123491 24 7 36794 48 45967 8092 1572 6495 176 233 5678 26876 2085 75 306 1000000000000 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...
result:
wrong answer 7th numbers differ - expected: '102', found: '200'