QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#430562#8769. Champernowne SubstringAfterlife#WA 252ms3844kbC++206.1kb2024-06-03 23:32:392024-06-03 23:32:39

Judging History

你现在查看的是最新测评结果

  • [2024-06-03 23:32:39]
  • 评测
  • 测评结果:WA
  • 用时:252ms
  • 内存:3844kb
  • [2024-06-03 23:32:39]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
const int mod = 998244353;
string s;
__int128 num;
int pos;
void upd(__int128 nm , int p) {
    if(num == -1 || nm < num) {
        num = nm ; pos = p;
    }
    else if(num == nm) {
        pos = min(pos , p);
    }
    return ;
}
string to_str(__int128 x , int len = 0) {
    string ans ;
    while(x) {
        ans += ((int)(x % 10) + '0') ;
        x /= 10;
    }
    while(ans.size() < len) ans += "0" ;
    reverse(ans.begin() , ans.end()) ;
    return ans;
}
int get_mat(const string& a,const string& b) {
    // cout <<b << '\n';
    for(int i = 0;i + b.size() - 1 < a.size();i++) {
        bool f = 1;
        for(int j = 0;j < b.size();j++) {
            if(!(b[j] == '?' || (b[j] == a[i + j ]))) {
                f = 0 ; break ;
            }
        }
        if(f) return i;
    }
    return -1;
}
int sump(__int128 x) {
    
    string w = to_str(x) ;
    // cout << w << '\n';
    int ans = 0;
    int pw[30] = {0} ;
    pw[0] = 1;
    for(int i = 1;i <= 29;i++) pw[i] = 10LL * pw[i - 1] % mod;
    for(int l = 1 ; l < w.size() ; l++) {
        ans = (ans + 1LL * l * (pw[l] - pw[l - 1] + mod)) % mod;
    }
    for(int i = 0;i < w.size();i++) {
        int len = w.size() - i - 1;
        if(i == 0) ans = (ans + 1LL * w.size() * (w[i] - '0' - 1) * pw[len]) % mod;
        else ans = (ans + 1LL * w.size() * (w[i] - '0') * pw[len]) % mod;
    }
    return ans;
}
__int128 to_int(string s) {
    __int128 ans = 0;
    for(int i = 0;i < s.size();i++) ans = (ans * 10 + s[i] - '0') ;
    return ans;
}
void solv() {
    cin >> s;
    string ss = "1" + s;
    for(auto &x : ss) x = (x == '?' ? '0' : x) ;
    num = to_int(ss); pos = 1;

    for(int l = 1;l <= s.size();l++) {
        ///
        __int128 k = 0;
        for(int j = 0;j < l;j++) k = k * 10 + 9;
        string cur ;
        int d = (s.size() / l + 1) ;
        for(__int128 x = k - d; x <= k + d ; x++) {
            if(x < 0) continue ;
            cur += to_str(x) ;
        }
        // cout << "TEST " << cur <<' ' << s << '\n';
        int pos = get_mat(cur , s) ;
        // cout << pos << '\n';
        if(pos != -1) {
            int curp = 0;
            for(__int128 x = k - d; x <= k + d ; x++) {
                if(x < 0) continue ;
                int len ;
                if(x <= k) len = l ;
                else len = l + 1;
                if(curp + len <= pos) {curp += len ; continue ;}
                else {
                    upd(x , pos - curp) ;break ;
                }
            }
        }
        for(int j = 0;j < l;j++) {
            vector<string> vec ;
            string w ; for(int x = 0 ; x < j;x++) w += "?" ;
            for(int x = 0;x < s.size();x++) {
                w += s[x] ;
                if(w.size() == l) {
                    vec.push_back(w) ; w = "" ;
                }
            }
            if(w.size()) {
                while(w.size() < l) w += "?" ;
                vec.push_back(w);
            }
            for(int k = l - 1 ; k >= 0;k--) {
                bool f = 1;
                string fir ;
                for(int a = 0 ; a < l;a++) fir += '?' ;
                for(auto &s : vec) {
                    for(int p = 0 ; p < k;p++) {
                        if(s[p] != '?') {
                            if(fir[p] == '?') fir[p] = s[p];
                            else if(fir[p] != s[p]) {f = 0 ; break ;}
                        }
                    }
                    if(!f) break ;
                }
                if(!f) continue ;
                __int128 head = 0;

                for(int p = 0;p < k;p++) {
                    if(fir[p] == '?') {
                        if(p == 0) fir[p] = '1' ;
                        else fir[p] = '0' ;
                    }
                    head = head * 10 + fir[p] - '0' ;
                    if(p == 0 && fir[p] == '0') f = 0;
                }
                if(!f) continue ;

                for(int p = k ; p < l;p++) head = head * 10 ;

                __int128 a9 = 0 , lv , upper , bg;
                for(int p = 0 ; p < l - k - 1 ; p++) a9 = a9 * 10 + 9;
                upper = a9 * 10 + 9; 
                for(__int128 lst = a9 - vec.size() ; lst <= a9 ; lst++) {
                    if(lst < 0) continue ;
                    for(int d = 0 ; d < 9;d++) { /// k这一位
                        if(k == 0 && d == 0) continue ;

                        lv = d * (a9 + 1) + lst ;
                        bg = lv + head;
                        bool f = 1;
                        for(auto &s : vec) {
                            if(lv > upper) {f = 0 ; break ;}
                            string w = to_str(lv , l - k) ;
                            for(int p = k ; p < l ; p++) {
                                if(!(s[p] == '?' || s[p] == w[p - k])) {
                            // if(l == 7 && j == 0 && bg == 1309997) {
                            //     cout << "Bad Mat " << s <<' ' << w << '\n';
                            //     cout << to_str(a9) <<' ' << to_str(lst) <<' ' << to_str(lv) <<' ' << d << '\n';
                            //     cout << "k = " << k << '\n';
                            // }
                                    f = 0 ; break ;
                                }
                            }
                            if(!f) break ;
                            lv++ ;
                        }
                        if(!f) continue ;
                        // if(bg == 0) {
                        // cout << "on " << l <<' ' << k <<' ' << to_str(bg) << '\n';
                        // for(auto s : vec) cout << s << '\n';
                        // }
                        upd(bg , j) ;
                    }
                }
                
            }
        }
    }
    int ans = (sump(num ) + pos + 1 ) % mod;
    // cout << to_str(num) << ' ' << pos << '\n';
    cout << ans << '\n';
}
int main() {
    ios::sync_with_stdio(false) ; cin.tie(0) ; 
    int t ; cin >> t;
    while(t--) solv() ;
    return 0;
}

詳細信息

Test #1:

score: 100
Accepted
time: 35ms
memory: 3524kb

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: 153ms
memory: 3808kb

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: 102ms
memory: 3560kb

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: 175ms
memory: 3588kb

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: 103ms
memory: 3568kb

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: 146ms
memory: 3840kb

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: 33ms
memory: 3812kb

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: 84ms
memory: 3584kb

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: 45ms
memory: 3568kb

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: 147ms
memory: 3844kb

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: 162ms
memory: 3552kb

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: 201ms
memory: 3568kb

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: 152ms
memory: 3560kb

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: 205ms
memory: 3560kb

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: 220ms
memory: 3556kb

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: -100
Wrong Answer
time: 252ms
memory: 3556kb

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
6
148888874

result:

wrong answer 9th lines differ - expected: '7', found: '6'