QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#408314#1372. Rainbow NumbersTheSleepyDevilAC ✓154ms80580kbC++142.4kb2024-05-10 02:33:232024-05-10 02:33:24

Judging History

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

  • [2024-05-10 02:33:24]
  • 评测
  • 测评结果:AC
  • 用时:154ms
  • 内存:80580kb
  • [2024-05-10 02:33:23]
  • 提交

answer

    /*
     Hell, 'til I reach Hell, I ain't scared
     Mama checkin' in my bedroom, I ain't there
                                                */
    #include<bits/stdc++.h>
    #include <ext/pb_ds/assoc_container.hpp>
    #include <ext/pb_ds/tree_policy.hpp>
    using namespace __gnu_pbds;
    using namespace std;

    #define Major  ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    #define TxtIO   freopen("input.txt","r",stdin); freopen("output.txt","w",stdout);
    #define read(a,n) for(int i = 0 ; i<n ; i++) cin>>a[i];
    #define write(a) for(auto x : a) cout<<x<<" ";
    #define int long long
    #define pb push_back
    #define all(a)  a.begin(),a.end()
    #define el "\n"

    typedef tree<int, null_type, less_equal<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;

    const int inf=4e18;

    int dx[]={1,0,-1,0,1,1,-1,-1};
    int dy[]={0,1,0,-1,1,-1,1,-1};

    const int mod=998244353;
    const int MAX =2e5+7;

    //---------------------------Function----------------------------------//
    int dp[MAX][11][2][2];
    int add(int x,int y){
        return (x%mod + y%mod)%mod;
    }
    int solve(string &s,int idx,int last,bool less,bool started){
        if(idx==s.size())return 1;
        int &ret=dp[idx][last][less][started];
        if(~ret)return ret;
        ret=0;
        for(int i=0;i<10;i++){
            if(!less&&i>(s[idx]-'0'))break;
            if(i==last && started)continue;
            int lesser=(i<(s[idx]-'0'));
            ret=add(ret,solve(s,idx+1,i,lesser|less,started|(i>0)));
            while(ret<0)ret+=mod;
        }
        return ret;
    }
    void TestCake(){
        string l,r;cin>>l>>r;
        memset(dp,-1,sizeof dp);
        int ansl=solve(l,0,0,0,0);
        memset(dp,-1,sizeof dp);
        int ansr=solve(r,0,0,0,0);
        int ans=add(-ansl,ansr);
        int ok=0;
        for(int i=1;i<l.size();i++){
            if(l[i]==l[i-1])ok=1;
        }
        ans=add(ans,!ok);
        while(ans<0)ans+=mod;
        ans%=mod;
       
        cout<<ans<<el;
    }
    //------------------------------Main---------------------------//
    signed main(){
        Major
        int T = 1;
//        cin >> T;
        while(T--){
            TestCake();
        //       cerr << "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n";
        }
        return 0;
    }

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 7ms
memory: 72312kb

input:

3
65

output:

58

result:

ok single line: '58'

Test #2:

score: 0
Accepted
time: 15ms
memory: 72508kb

input:

37
524

output:

403

result:

ok single line: '403'

Test #3:

score: 0
Accepted
time: 4ms
memory: 72328kb

input:

974
9522

output:

6271

result:

ok single line: '6271'

Test #4:

score: 0
Accepted
time: 7ms
memory: 72276kb

input:

50518
71177

output:

13592

result:

ok single line: '13592'

Test #5:

score: 0
Accepted
time: 12ms
memory: 72280kb

input:

31718
829025

output:

477007

result:

ok single line: '477007'

Test #6:

score: 0
Accepted
time: 3ms
memory: 72276kb

input:

2673659
3522358

output:

444961

result:

ok single line: '444961'

Test #7:

score: 0
Accepted
time: 11ms
memory: 72316kb

input:

68790054
74835016

output:

3158763

result:

ok single line: '3158763'

Test #8:

score: 0
Accepted
time: 8ms
memory: 72508kb

input:

17596932
830146213

output:

355204747

result:

ok single line: '355204747'

Test #9:

score: 0
Accepted
time: 7ms
memory: 72512kb

input:

4559302681
8460113494

output:

551444164

result:

ok single line: '551444164'

Test #10:

score: 0
Accepted
time: 7ms
memory: 72256kb

input:

69096117055
78607961801

output:

325094872

result:

ok single line: '325094872'

Test #11:

score: 0
Accepted
time: 4ms
memory: 72336kb

input:

73724561911
889698372081

output:

41274511

result:

ok single line: '41274511'

Test #12:

score: 0
Accepted
time: 85ms
memory: 77100kb

input:

394508574650091022512909571921114492507182694804026914557940803351210811949294279029752773817948937368669076640956044457423812581727430884005816206959427698347341885326394187628757727906699306514383875164462186324492548299764354798393930933304229249368412800790454859889329435645073095955728789171702...

output:

756013076

result:

ok single line: '756013076'

Test #13:

score: 0
Accepted
time: 113ms
memory: 78236kb

input:

422014715369079097925608576097053393447341302972956361410316610182985064145389774113205524523087296205181295465843585593935732826938976987802078878325619776564276368817692500878159975485238243080947879152156568498810626499536300978108439515929336284446557185830049933423981614786282183661906272862517...

output:

910290565

result:

ok single line: '910290565'

Test #14:

score: 0
Accepted
time: 80ms
memory: 76684kb

input:

629396096057468187536008660523981385068079952319349471675185632997043167437177453007637825175211086119803071189551537498462585481009493935144671873254853670403033132984991648864417820658966727747779525379302774945537232349542662015587544507173985564040097599634973358738856506578728656284970453992909...

output:

206648751

result:

ok single line: '206648751'

Test #15:

score: 0
Accepted
time: 146ms
memory: 80296kb

input:

199626343357951152976038386589371212733444160365124954296963099284660388005029305337631801634925234172185609304248376473380083105406411526104699402946739597346435624847786625103712052504238131893994452042122278321653786103152589778095076110445791863192424539886648381508796263443067972336469068586450...

output:

718053737

result:

ok single line: '718053737'

Test #16:

score: 0
Accepted
time: 83ms
memory: 76532kb

input:

416808467195722010717127833402137108329359612596927289691425470111656493652261905429087663641343249238712155727095465434341074450710321551466047302616559139335310175711953306158251471371425473739854879886873588044584832688470163949674325274969568377528513249445556658110466623454653717769390783039308...

output:

182246952

result:

ok single line: '182246952'

Test #17:

score: 0
Accepted
time: 154ms
memory: 80580kb

input:

123343027257017651518445188954611335922116205762639210047994511861224460368751657727094916366693982441252856763608738504776743932824426227912514755331398286427843785571450458430865025310462426643461359293139384334713525243669047961510996307364053779014126345116040064878119666567405582997008526481779...

output:

635917051

result:

ok single line: '635917051'

Test #18:

score: 0
Accepted
time: 106ms
memory: 78000kb

input:

555447303587984935082102315240572317427032365494842712316690651708012590452140846568605875046914403037659471823547090546652528677148568592178117915826208879342008567398432355062521103014413587212424186325363147338980680164777568474515738920096377955187197462657654532855548271944324696377703605930926...

output:

609877234

result:

ok single line: '609877234'

Test #19:

score: 0
Accepted
time: 40ms
memory: 74336kb

input:

346936986726555509250989806448369042413425814612507036715378765301213065566598275883962847974103750963496684004841771015308222144469853044247988854848255290418003505127692437063318505453103279396876102565651692643033740443939691521078223172329110270567092570987328376283086698808515395858671126318600...

output:

140021677

result:

ok single line: '140021677'