QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#427880 | #8769. Champernowne Substring | ucup-team3510# | WA | 153ms | 7060kb | C++14 | 2.5kb | 2024-06-01 16:17:51 | 2024-06-01 16:17:54 |
Judging History
answer
#include <bits/stdc++.h>
#define lll __int128
using namespace std;
lll pw[31],pre[31];string str;int n;
void write(lll x){if(x<10)putchar(x+'0');else write(x/10),putchar(x%10+'0');}
int bits(lll x){int c=0;while(x)++c,x/=10;return c;}
string to_s(lll x)
{
string s;
while(x)
{
s+=x%10+'0';
x/=10;
}
reverse(s.begin(),s.end());return s;
}
lll ID(lll x)
{
int lg=bits(x);lll ans=pre[lg-1];
ans+=(x-pw[lg-1]+1)*lg;
return ans;
}
lll ans=1e36,cans=1e36;
int match(string s,string t)
{
for(int i=0;i+t.size()-1<s.size();++i)
{
bool ok=1;
for(int j=0;j<t.size();++j)if(t[j]!='?'&&s[i+j]!=t[j]){ok=0;break;}
if(ok)return i;
}
return -1;
}
set<lll> st;
void check(lll x)
{//printf("check(");write(x);printf(")\n");
if(st.find(x)!=st.end())return;
st.insert(x);
int lg=bits(x);
if(x>cans)return;
string s;
lll y=x;
while(s.size()<n-1+lg)s+=to_s(y++);
// printf("s:%s\n",s.c_str());
int tt=match(s,str);
if(~tt)
{
// printf("success\n");
ans=ID(x-1)+1+tt;
cans=x;
}
}
struct Limit{int a,b,c;Limit(){}Limit(int _a,int _b,int _c){a=_a;b=_b;c=_c;}};
int w[31][31],ww[31];
void solve(vector<Limit> vl,int k)
{
int mxa=0;
for(auto L:vl)mxa=max(mxa,L.a);
for(int i=0;i<=mxa;++i)for(int j=1;j<=k;++j)w[i][j]=-1;
for(auto L:vl)
{
if(~w[L.a][L.b]&&w[L.a][L.b]!=L.c)return;
w[L.a][L.b]=L.c;
}
for(int i=k;i>1;--i)
{
for(int j=1;j<=k;++j)ww[j]=-1;bool ok=1;
for(int j=0;j<=mxa;++j)
{
for(int _=1;_<i;++_)if(~w[j][_])
{
if(~ww[_]&&ww[_]!=w[j][_]){ok=0;break;}
ww[_]=w[j][_];
}
if(!ok)break;
}
if(ok)
{
for(int j=1;j<i;++j)if(!~ww[j])ww[j]=j==1;
lll W=0;
for(int j=1;j<i;++j)W=W*10+ww[j];
W*=pw[k-i+1];
for(int _=0;_<=8;++_)for(int __=1;__<=mxa;++__)check(W+(_+1)*pw[k-i]-__);
}
}
}
void dosolve(int k)
{
for(int j=0;j<k;++j)
{
vector<Limit> Lim;
for(int i=0;i<n;++i)if(str[i]!='?')
{
Lim.push_back(Limit((j+i)/k,(j+i)%k+1,str[i]-'0'));
}
solve(Lim,k);
}
}
int TT;
int main()
{
pw[0]=1;for(int i=1;i<=36;++i)pw[i]=10*pw[i-1];
pre[0]=0;for(int i=1;i<=30;++i)pre[i]=pre[i-1]+i*(pw[i]-pw[i-1]);
// printf("pre:");for(int i=1;i<=30;++i)write(pre[i]),putchar(32);putchar(10);
scanf("%d",&TT);while(TT--)
{
cin>>str;n=str.size();
ans=1e36,cans=1e36;
st.clear();
for(int i=1;i<=999;++i)check(i);
for(int i=4;i<=25;++i)for(int j=1;j<=25;++j)check(pw[i]-j);
for(int i=4;i<=25;++i)dosolve(i);
// printf("ans:");write(ans);putchar(10);
printf("%d\n",(int)(ans%998244353));
}
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 56ms
memory: 6460kb
input:
9 0 ???1 121 1?1?1 ??5?54?50?5?505?65?5 000000000000 ?2222222 ?3????????9??8???????1??0 9?9??0????????????2
output:
11 7 14 10 314159 796889014 7777 8058869 38886
result:
ok 9 lines
Test #2:
score: 0
Accepted
time: 101ms
memory: 7060kb
input:
10 0000000000000000000000000 0000000?002100000000000?0 6999?999?999999989?999999 0???0?1000?0??000?????0?1 9??9?999998?9?999999100?0 96?9997999?8999991????010 99?99??999999999??????99? ?0?0000?00000000?0210?0?0 99?999?999?99?9??999?9?9? 9?????9?99?99??9??99??9??
output:
545305036 574985081 788888865 5889591 902934046 488873 902034054 830780534 68888820 5882870
result:
ok 10 lines
Test #3:
score: 0
Accepted
time: 144ms
memory: 5292kb
input:
10 23573?0208935200503593500 08?9?1188980?661?18161467 22000103111010?24490??02? 4?129184?3644311331226625 9014217281609919609168?18 27809?1808?34646796569990 5116137658333853138917519 8778798398090800698?93888 742?9472125?9529272277272 5260238541343?22235629222
output:
108802929 797951281 758593545 919282423 660254768 34219412 452740345 687192108 692870314 277899385
result:
ok 10 lines
Test #4:
score: 0
Accepted
time: 143ms
memory: 6828kb
input:
10 98898918898?0109088100808 ???08?9???1??????88?????? 8?1???????0118????00???8? ??1880????1?8???111101108 ???????11??1????0???000?? ?9?01???0????9????8???9?? ???1?1?????1????90?0????0 ??8?????????18?9????????? 8????91?8???????????????9 ??0????1?????9??8?909???0
output:
397005130 796170672 681417627 201652995 493829373 76730467 798698896 6434 43334 443792
result:
ok 10 lines
Test #5:
score: 0
Accepted
time: 152ms
memory: 5716kb
input:
10 012003??1?0?591??0?30?30? 1000?0?1100000?731?101211 ?0?11?80101111?1??1328??? 411410110174?154311111111 20005??141101015?0?1?0??1 5??81010????10???237300?0 ?3605?3611014?09?446?6313 1110015171261071000007001 991?11162011?0191117?0410 ?200500??003??60??01900?2
output:
900307781 839110958 981675858 995851013 389598828 122551361 79267861 295093505 388362258 286706944
result:
ok 10 lines
Test #6:
score: 0
Accepted
time: 153ms
memory: 6656kb
input:
10 ?150?7??2???902??0?80?70? 1??????11??????001?1?1017 ???12???1?5111?1??3?0???? 61165?11?196?376621133111 0???0??1041?5?20???1????1 0???3?2?????1????70?0???? ?7????7?11?48????98???747 1420?2717247207100?0?8??1 001?13185031??301119??71? ?5??0??????7??0????10???5
output:
864484608 74700832 681727245 536368659 226329329 975189011 448648057 967696005 376743109 173528449
result:
ok 10 lines
Test #7:
score: 0
Accepted
time: 88ms
memory: 6252kb
input:
10 2??0?0??4??3 ??0?64?5???1???? ??????????01???0017???0 1147???1?1? 07?060????0?? 0706457?760130 ??4????3???4? 199?0?19?0?2262880 3675036117 032?????8?0??00??
output:
6099056 69020130 488979 68978070 41928 657141248 909 87550531 643195723 982967061
result:
ok 10 lines
Test #8:
score: -100
Wrong Answer
time: 130ms
memory: 5280kb
input:
10 1004024914000141171664179 4112700045099296212010057 2000700072177165003008355 5147124088080418420102215 0111131163261117111189161 0000000507001000083001045 4616130013212189231581163 6370033693059001070063068 2600011505817800101005111 8171898166180081571808187
output:
571303254 485994730 881341707 302237585 319228799 682761479 494203217 307458184 948671187 770194561
result:
wrong answer 1st lines differ - expected: '492541635', found: '571303254'