QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#661045 | #8769. Champernowne Substring | fryan | WA | 993ms | 3976kb | C++17 | 7.1kb | 2024-10-20 14:28:13 | 2024-10-20 14:28:14 |
Judging History
answer
#include "bits/stdc++.h"
using namespace std;
#define int int64_t
#define i128 __int128_t
#define all(x) begin(x), end(x)
#define sz(x) (int) (x).size()
const int mod = 998244353;
string s;
std::string to_string(__int128 num) {
if (num == 0) return "0";
bool is_negative = num < 0;
std::string result;
if (is_negative) num = -num;
while (num > 0) {
result += '0' + (num % 10); // Append last digit
num /= 10; // Remove last digit
}
if (is_negative) result += '-'; // Add negative sign if needed
std::reverse(result.begin(), result.end()); // Reverse to correct order
return result;
}
namespace util {
string qmk[500];
void init() {
qmk[0] = "";
for (int i=1; i<500; i++) {
qmk[i] = qmk[i-1]+"?";
}
}
int len(i128 s) {
return sz(to_string(s));
}
i128 ksm(int a, int b) {
i128 res=1;
for (int i=0; i<b; i++) {
res = res*a;
}
return res;
}
i128 answer(i128 v) {
if (v==0) return 0;
v--;
if (v==0) return 0;
i128 f = len(v);
i128 pv = ksm(10,f-1);
return f*(v-pv+1)+answer(pv);
}
__int128 sto128(const std::string& str) {
__int128 result = 0;
bool is_negative = (str[0] == '-');
size_t start = is_negative ? 1 : 0;
for (size_t i = start; i < str.size(); ++i) {
if (str[i] < '0' || str[i] > '9') {
throw std::invalid_argument("Invalid character in string.");
}
result = result * 10 + (str[i] - '0');
}
return is_negative ? -result : result;
}
}
namespace brutal_check {
const int LIM = 9999;
bool equal(string s1, string s2) {
if (sz(s1) != sz(s2)) return 0;
for (int i=0; i<sz(s1); i++) {
if (s1[i]!=s2[i] && s1[i]!='?' && s2[i]!='?') return 0;
}
return 1;
}
bool check(i128 start,string s) {
string s1 = "";
for (i128 i=start; sz(s1) < sz(s); i++) {
s1 = s1+to_string(i);
}
s1.resize(sz(s));
return equal(s,s1);
}
i128 cp10() {
i128 res = -1;
for (int len = 1; len <= 26; len++) {
i128 v = util::ksm(10,len);
i128 xx = util::answer(v);
for (int expa = 0; expa < 60; expa++) {
string ss = util::qmk[expa]+s;
for (int cv = v; cv >= max((i128)1,v-60); cv--) {
if (check(cv,ss)) {
i128 ans = util::answer(cv) + expa + 1;
if (res==-1) res = ans;
res = min(res,ans);
}
}
}
}
return res;
}
i128 go() {
i128 res = -2;
for (int i=1; i<=LIM; i++) {
int l = util::len(i);
for (int pad=0; pad<l; pad++) {
string ss = util::qmk[pad]+s;
if (check(i,ss)) {
i128 ans = util::answer(i)+pad;
if (res==-2) res = ans;
else res = min(res,ans);
}
}
}
return res+1;
}
}
namespace large_check {
const int LIM = 26;
/*
casework on:
- length of numbers [assume stays constant for this one]
- greatest index that changes in value
- from ...x99999 to ...x+100000
*/
int cor[26];
bool compatible(string s, string s1) {
assert(sz(s)==sz(s1));
memset(cor,-1,sizeof(cor));
for (int i=0; i<sz(s); i++) {
if ('a' <= s1[i] && s1[i] <= 'z' && s[i] != '?') {
int k = s1[i] - 'a';
int v = s[i] - '0';
if (cor[k]==-1) cor[k] = v;
if (cor[k] != v) return 0;
}
if ('0' <= s1[i] && s1[i] <= '9') {
int v = s1[i] - '0';
if (s[i]=='?') continue;
int v1 = s[i]-'0';
if (v != v1) return 0;
}
}
return 1;
}
i128 check_no_change(int len, string s, int pad=0) {
//pad s with additional ?s
int need = (len-sz(s)%len)%len;
s.resize(sz(s)+need,'?');
//fill in everything BUT units [they don't change]
char cur = 'a';
string s1; s1.resize(sz(s),'?');
for (int r=0; r+1<len; r++) {
for (int i=0; i*len<sz(s); i++) {
s1[i*len+r] = cur;
}
cur++;
}
if (!compatible(s,s1)) return -1;
if (cor[s1[0]-'a'] == 0) return -1;
for (int i=0; i<26; i++) {
if (cor[i]==-1) cor[i] = 0;
}
if (cor[s1[0]-'a'] == 0) cor[s1[0]-'a']=1;
for (int i=0; i<sz(s1); i++) {
if (i%len == len-1) continue;
s1[i] = '0'+cor[s1[i]-'a'];
}
for (int s0 = 0; s0<10; s0++) {
int cv = s0;
string s2 = s1;
for (int i=0; i*len<sz(s); i++) {
if (cv==10) return -1;
s2[i*len+len-1] = cv+'0';
cv++;
}
if (compatible(s,s2)) {
string first = s2.substr(0,len);
i128 ans = util::sto128(first);
i128 res = util::answer(ans)+pad+1;
return res;
}
}
return -1;
}
i128 check(int len, int ind, string s, int pad=0) {
//pad s with additional ?s
int need = (len-sz(s)%len)%len;
s.resize(sz(s)+need,'?');
string s1; s1.resize(sz(s),'?');
i128 lok = len-ind%len; //length of known
i128 vok = util::ksm(10,lok)-1; //value of known
i128 iok = ind/len; //index [in lengths] of known
for (int i=0; i*len<sz(s); i++) {
string v = to_string(vok-(iok-i));
v = v.substr(sz(v)-lok,sz(v));
s1.replace(i*len + ind%len, lok, v);
}
//r=ind%len+1
int rr = ind%len-1;
for (int i=0; i*len<sz(s); i++) {
int pos = i*len+rr;
if (pos < ind) s1[pos] = 'a';
else s1[pos] = 'b';
}
char cur = 'c';
for (int r=ind%len-2; r>=0; r--) {
for (int i=0; i*len<sz(s); i++) {
int pos = i*len+r;
s1[pos] = cur;
}
cur++;
}
if (!compatible(s,s1)) return -1;
if (cor[0]==9 || cor[1]==0) return -1;
if (cor[0]==-1 && cor[1]==-1) {
cor[0] = 0, cor[1] = 1;
} else if (cor[0]==-1) {
cor[0] = cor[1]-1;
} else if (cor[1]==-1) {
cor[1] = cor[0]+1;
} else if (cor[0]+1!=cor[1]) {
return -1;
}
if (cor[s1[0]-'a']==0) return -1;
for (int i=2; i<26; i++) {
if (cor[i]==-1) cor[i] = 0;
}
if (cor[s1[0]-'a']==0) cor[s1[0]-'a']=1;
string first = s1.substr(0,len);
for (int i=0; i<len; i++) {
if ('a' <= first[i] && first[i] <= 'z') {
first[i] = '0' + cor[first[i]-'a'];
}
}
i128 ans = util::sto128(first);
i128 res = util::answer(ans)+pad+1;
return res;
}
i128 go() {
i128 res = -1;
for (int len=2; len<=LIM; len++) {
for (int pad=0; pad<len; pad++) {
string ss = util::qmk[pad]+s;
int rem = (len-sz(ss)%len)%len;
ss.resize(sz(ss)+rem,'?');
for (int ind=0; ind<sz(ss); ind++) {
if (ind%len==0) continue;
i128 v = check(len,ind,ss,pad);
if (v==-1) continue;
if (res==-1) {
res = v;
}
res = min(res,v);
}
}
}
for (int len=2; len<=LIM; len++) {
for (int pad=0; pad<len; pad++) {
string ss = util::qmk[pad]+s;
i128 v = check_no_change(len,ss,pad);
if (v==-1) continue;
if (res==-1) res = v;
res = min(res,v);
}
}
return res;
}
}
i128 minn(i128 a, i128 b) {
if (a==-1) return b;
if (b==-1) return a;
return min(a,b);
}
void solve() {
cin>>s;
i128 c = minn(brutal_check::cp10(),minn(brutal_check::go(),large_check::go()));
c %= mod;
cout<<to_string(c)<<"\n";
}
signed main() {
ios::sync_with_stdio(false); cin.tie(nullptr);
util::init();
int t; cin>>t;
while (t--) {
solve();
}
return 0;
}
詳細信息
Test #1:
score: 100
Accepted
time: 575ms
memory: 3972kb
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: 876ms
memory: 3764kb
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: 841ms
memory: 3684kb
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: 866ms
memory: 3636kb
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: 838ms
memory: 3692kb
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: 853ms
memory: 3756kb
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: 677ms
memory: 3680kb
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: 0
Accepted
time: 819ms
memory: 3936kb
input:
10 1004024914000141171664179 4112700045099296212010057 2000700072177165003008355 5147124088080418420102215 0111131163261117111189161 0000000507001000083001045 4616130013212189231581163 6370033693059001070063068 2600011505817800101005111 8171898166180081571808187
output:
492541635 485994730 881341707 302237585 319228799 682761479 494203217 307458184 948671187 770194561
result:
ok 10 lines
Test #9:
score: 0
Accepted
time: 718ms
memory: 3684kb
input:
10 9999??1?24109 9961?9?99?9?17??9?9981?9 ?55139?310? 01060999911010?100001 ????1???0???0 1999?9?9??1?1?99 ?6?098?????0?91?06? ??9?9?9920 1009??99?9?83011009 ?08815?9?290?6??8159992?
output:
701914982 502544507 838514018 198720051 210 1088344 69369676 88485 208314295 325404847
result:
ok 10 lines
Test #10:
score: 0
Accepted
time: 849ms
memory: 3960kb
input:
10 ???9?9????9??1????0?00?0? ?19??5?6705?2006?7?705420 ?8?99??9?10????00?000???? 26??9???8??1862?9?99???1? ?1?811????119911?1801?0?1 99?0?7?400?????0?7???0??0 9981?80?15??9?99??9??8?2? 87??9787249?8724?98725008 ?1???1??7??9?????7??9???? 529999810002?2999991000??
output:
488877 578261397 68888881 922387376 922701699 750962293 869492708 5123872 795205985 107899748
result:
ok 10 lines
Test #11:
score: 0
Accepted
time: 860ms
memory: 3760kb
input:
10 ?????????????0??0?0?0??0? ?7??1???99???991?070??000 30???7??????8???1??????1? ??45??9?99?9??50????0?09? ?6???0?????9????6?6???0?0 1?????71??811??12?0?2???? ?0???0???0???0??0?0?????0 1????999?8???1?8??0?0?088 0??3?000?81?0?030??0181?0 ????9?9??99??0??0?81???00
output:
38878 974988866 7995940 207215288 789434908 3675 2915 656463525 46595272 162777032
result:
ok 10 lines
Test #12:
score: 0
Accepted
time: 865ms
memory: 3688kb
input:
10 ???????2?6?9?99????9??6?? ?9?9??6???9?9??2????0?6?? ?13?11?1????7?1??????1?99 ??9???9011??00?999?9??1?? 0?0?1??0?2?00????1??110?2 ?6?301?1818??9??????11??? ?1????8?????99??2???????2 ?9?????4????9?9??73?49??? ???9?7????98??9?????????? ?96??9?7?????????99????9?
output:
785875062 118488877 347574749 926770730 39160338 299823179 6742876 217198712 548872 438872
result:
ok 10 lines
Test #13:
score: 0
Accepted
time: 852ms
memory: 3640kb
input:
10 ???97??0?99???07?99?00800 ?99??3?04??9??310??000?3? 2????1?1?????001???1??632 ??1???????????39?????9??? 0???5?60?9???????9?2????0 9??99?9?93?191???9??99993 9733?98???993?1?03?101331 9??07?30000207?3?0?1?0703 ?9?86?00?00086??0?00????0 ????1?99??181?9????8??00?
output:
5944871 70013524 400601421 40868 35709572 642051114 154378 753914535 641178416 83376873
result:
ok 10 lines
Test #14:
score: 0
Accepted
time: 879ms
memory: 3640kb
input:
10 9?20?0???0???00???01?0??0 9?9?1?9???19??97????????? ??9????1?1??00?0??1?9???? 9??6168??9?9?9??6?9??998? 9??963702???9?9?9?9???0?? 9?????????9?9??8?9???9?9? ?07????0??0?????0????0??? 9???9????1???9?99?9???1?9 5?8??99???????89??999?9?7 ????9?74???9?9???????????
output:
690644535 1083462 798698973 995370331 446157661 5882928 530890 148240876 882732928 69688682
result:
ok 10 lines
Test #15:
score: 0
Accepted
time: 895ms
memory: 3680kb
input:
10 9??9?53??000?3?0?????0?0? ?8???9??72???9????28??9?? 999?9180?0??????????0???? 9?99???00??0?0?????0????? 9?????9??000?????0????00? ?999???99?0?????0???????? ?????0?0??5?80???00?????? 9??????????????5?9??9??9? ?????9?????8?9?999??????0 ???????61??9?9????9??????
output:
35988885 854409694 510644532 488886 488882 38881 789346093 1059429 438873 5952561
result:
ok 10 lines
Test #16:
score: 0
Accepted
time: 993ms
memory: 3976kb
input:
10 ?199???9??5?999??9965?9?9 ????0??????9??5?????????? ??????????0?0?00??1????0? 7????9?1?????0??????????? ???????0???????????60???? ????9??????0??9????4????? ????????????????????????? ????0??20?0??????????0??? ????0???????????????????? ????999??999??????????0?2
output:
885690430 167 488883 2883 39174 782884 1 88923 7 148888874
result:
ok 10 lines
Test #17:
score: 0
Accepted
time: 857ms
memory: 3744kb
input:
10 ?86399?86??99864000864?01 ????998??99??0?5???5?02?? 769999??9?999???????0???? ??89?6?8?8???99?1?0???9?? ??9??71?2099?9?8?32?99999 9?99853?99?999?400000?05? 9??????9??99?9??10??00??0 07908???????11?129?3?14?? 976?9???9?6?006?0?????63? ??76?????9?9???????9???6?
output:
5072877 18879 4088877 298375 119956628 755911464 5888874 2612 24080 334377
result:
ok 10 lines
Test #18:
score: 0
Accepted
time: 886ms
memory: 3960kb
input:
10 ?529???2987??9?753?075?01 72?9???29??9??0?0??30??01 9984?99999??200?00?42?00? 9???????999???1????????1? 9?9?869?99?999?0????00070 7?5989599?60?960196?296?3 ??418??1894190??91419??19 ??????????999????99??9??? 99?9989759999?99??0?0?00? ?????????8????9???9?????1
output:
365375 1688877 324888879 68976879 199422758 37281 15640 2849 686934051 6438
result:
ok 10 lines
Test #19:
score: 0
Accepted
time: 860ms
memory: 3752kb
input:
10 79?95?9?969??99?6??0009?9 7?9??9?8?999?9?900???0?0? ??6??6?86?7699??7700?7?7? ????8?0?99?92??0?0?????0? 99?99?8499?9??995?????0?0 7???82?3?21?????1?14???4? 7??879?081?28?8?8??6?78?? 9?99999?9?3?00?000?30000? 1?9?1998199920?0?00?2?0?2 ?4???84???????????????1??
output:
66760875 61888875 3955076 12958878 395911462 7441 144 272934057 6878 2423
result:
ok 10 lines
Test #20:
score: 0
Accepted
time: 857ms
memory: 3792kb
input:
10 87??9?88?1999??72000?87?? ?0???5?998????9?1?????0?? ??99719?99????9?9?920?0?? ??9??82?9999??3?000????00 ??????????100??1?00???0?? ?74918?91?4?2??9?1??2249? 77????9?????????8??????0? 75???????2?99???????5?4?? 9???9?9?9?9?0?9?0?9?0??5? 8?7999??938000000?800??01
output:
59928876 243875 1040873 14988877 38880 18560 2283 3203277 36880 292888881
result:
ok 10 lines
Test #21:
score: 0
Accepted
time: 877ms
memory: 3960kb
input:
10 10?9?9?8?10??9??9??1000?0 ???7?3??99???9986?4???99? ?9?4???????????9???????04 ??????9??????7????0???0?? ??1??4?????419?4?2004?2?1 999???7??9?9???000??80000 ???9???4??????0???40??0?0 ?5?????5??????????7????4? ????8?????????0??000???0? ??????7??????????9?????0?
output:
887888873 275445479 5952172 5678 209875 11488878 72092077 1515 488880 6790
result:
ok 10 lines
Test #22:
score: 0
Accepted
time: 850ms
memory: 3892kb
input:
10 9?7?9?8?9891???1????9???9 7?1?9?8914??9915?0????0?1 ????19?????????2??3?0???? ?9?99729?????9?99930?0?03 9?9???64????99??8?6??9?9? ?9?7?41????4?199?9?42?0?? 15?99997???99??????99999? 0999?7??099??8?7??9?9???? 7689999??97?768??99??9??? 39??9??9?4??00?000400?000
output:
6839 5378877 483 1688872 248146848 29828872 109688866 125688868 226398760 494155822
result:
ok 10 lines
Test #23:
score: 0
Accepted
time: 868ms
memory: 3936kb
input:
10 399?972?999?82?999?924000 ?4???9??99?87485???9????? ??2????9?99?98?56??9??999 99998?7?999?9995800000?00 ?68???0?17???7??????7???? ?????7???????3?????3????? 4974??4?95005??50?503??4? ????79??0?80??0?8??????0? 4????9????9999?????9?999? ?????99???8?99??926???00?
output:
15688870 470575554 195644357 987205107 125 268 1381 2283 148888849 305300167
result:
ok 10 lines
Test #24:
score: 0
Accepted
time: 850ms
memory: 3684kb
input:
10 ??98?9??0???130?????04??? 713999998139999991?0?00?0 97?691?99866919?99???20?? 9?79?99?8??9?99910?009100 3?99?7?9999839?99?4?0000? ?756856???05715?2??35??5? 65?9?9?9?8??00???038660?0 ????9??????99?9?????009?? 973?899?3???99?7?00037900 ??8??9999??9?9999?99???0?
output:
783 100888873 524248872 5348875 2288872 1592 613847821 5883474 2162876 820490516
result:
ok 10 lines
Test #25:
score: 0
Accepted
time: 915ms
memory: 3696kb
input:
10 ??7?9?99?699????000007000 ???9?????9??9???????????? ?99???99????000??0?0?000? ?4????4?9???9??4??0?4???? ??1????????2????0???0?027 ????????????91??????100?? 99999?25299?99?252999??92 79999779999??9?99?8??0?0? ??82???9999??0???0??0?0?0 ?????63?9??9??90????????0
output:
4088875 177 5888879 213380 802547346 489428 169400160 4688872 228888879 6563611
result:
ok 10 lines
Test #26:
score: -100
Wrong Answer
time: 852ms
memory: 3692kb
input:
10 999?9?73????9??8??9?9??99 99?9746?9??9984?4999?9??6 ??9??9?96????00??0?6?5??? 79??7?99987?99980?0??0?0? ??997?99??9??9999?9??0?00 ?349??234???????99?3??002 ?986999999?70??00?0700??? 99?9999?300???0???00???0? ???8?0??9???????4??00???3 7?646988646998?4700864?01
output:
682400159 80911455 53005937 388875 68888871 1298872 548888879 60644530 2306880 5077077
result:
wrong answer 5th lines differ - expected: '12888871', found: '68888871'