QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#812196#885. Keep Calm And Carry Offucup-team5071#AC ✓36ms22944kbC++202.3kb2024-12-13 12:46:532024-12-13 12:46:59

Judging History

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

  • [2024-12-13 12:46:59]
  • 评测
  • 测评结果:AC
  • 用时:36ms
  • 内存:22944kb
  • [2024-12-13 12:46:53]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;

typedef long long ll;

vector<int> read()
{
    vector<int> tmp;
    char ch = getchar();
    while (ch <= '9' && ch >= '0')
    {
        tmp.push_back(ch - '0');
        ch = getchar();
    }
    reverse(tmp.begin(), tmp.end());
    return tmp;
}

// vector<int> sol(vector<int> x, vector<int> y)
// {
// }

vector<int> i2vec(int x)
{
    vector<int> res;
    while (x)
    {
        res.push_back(x % 10);
        x /= 10;
    }
    return res;
}

void print(const vector<int> &a)
{
    // for (int i = 0; i < a.size(); ++i)
    for (int i = a.size() - 1; i >= 0; --i)
        cout << a[i];
    cout << "\n";
}

int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    vector<int> a = read();
    vector<int> b = read();
    // int mn = min(a.size(), b.size());
    int mx = max(a.size(), b.size());
    a.resize(mx, 0);
    b.resize(mx, 0);
    // print(a);
    // print(b);

    // vector<int> adda(a.size());
    // vector<int> addb(b.size());

    int i, j;
    j = -1;
    for (i = mx - 1; i >= 0; --i)
    {
        if (a[i] + b[i] >= 10)
        {
            for (j = i + 1; j < mx; ++j)
            {
                if (a[j] + b[j] < 9)
                {
                    j--;
                    break;
                }
            }
            j = min(j, mx - 1);
            break;
        }
    }
    if (j == -1)
    {
        cout << 0 << "\n";
        return 0;
    }
    // cout << "j: " << j << endl;
    vector<int> big = a;
    for (int x = j; x >= 0; --x)
    {
        if (a[x] > b[x])
        {
            break;
        }
        else if (a[x] < b[x])
        {
            big = b;
            break;
        }
    }
    vector<int> ans;

    bool jin = false;
    for (int i = 0; i <= j; ++i)
    {
        if (jin == false)
        {
            if (big[i] == 0)
            {
                ans.push_back(0);
            }
            else
            {
                ans.push_back(10 - big[i]);
                jin = true;
            }
        }
        else
        {
            ans.push_back(9 - big[i]);
        }
    }
    while (ans.size() > 1 && ans[ans.size() - 1] == 0)
    {
        ans.pop_back();
    }
    print(ans);
    // cout << ans << "\n";

    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 0ms
memory: 3624kb

input:

10
99

output:

1

result:

ok answer is '1'

Test #2:

score: 0
Accepted
time: 0ms
memory: 3824kb

input:

90
10

output:

10

result:

ok answer is '10'

Test #3:

score: 0
Accepted
time: 0ms
memory: 3484kb

input:

23425
487915

output:

12085

result:

ok answer is '12085'

Test #4:

score: 0
Accepted
time: 0ms
memory: 3564kb

input:

1
1

output:

0

result:

ok answer is '0'

Test #5:

score: 0
Accepted
time: 0ms
memory: 3616kb

input:

99
99

output:

1

result:

ok answer is '1'

Test #6:

score: 0
Accepted
time: 0ms
memory: 3532kb

input:

14
86

output:

14

result:

ok answer is '14'

Test #7:

score: 0
Accepted
time: 0ms
memory: 3788kb

input:

899999999999999999999
100000000000000000001

output:

100000000000000000001

result:

ok answer is '100000000000000000001'

Test #8:

score: 0
Accepted
time: 30ms
memory: 21108kb

input:

615357649595284099508435993883986571313695656691562389866620971630644953030429613681442060702023197532680463771166724257258948140032009435767225187778914625685600736964207275868974321513156027752788270804733647164380664571327109020774746630643814103150883559720458844636326901760106285413007100737536...

output:

226164757855375706179130034126837577710545348626568907238536520434546544085882446273981029021778063112888523241983297218947698252532826120194967039881313867888258883810876610793168815193851023510269144054457285631520878535365581681349042349672439715344120755176307571379581412256786498122023796566813...

result:

ok answer is '226164757855375706179130034126...1032113015742081980588406310856'

Test #9:

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

input:

100000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000...

output:

0

result:

ok answer is '0'

Test #10:

score: 0
Accepted
time: 26ms
memory: 21112kb

input:

946678535444896475642225008527348253117127344137446723931302495407581979054231432196768653557235697280697999349345542859864503525832718970888297969471590384454809084105146882526427617822167077225221683317423530502375438306992125794196668936915418103664819269986191955766257534524689071638219238188976...

output:

533214645551035243577749914726517468828726558625532760686975045924180209457685678032313464427643027193020006506544571401354964741672810291117020305284096155451909158948531174735723821778329227747783166825764694976245616930078742058033310630845818963351807300138080442337424654753109283617807618110239...

result:

ok answer is '533214645551035243577749914726...8583282299712982139175537021362'

Test #11:

score: 0
Accepted
time: 31ms
memory: 22420kb

input:

794946477760061325408107597512810946289384941381736255316518687888511341258007534679058032849319730631613743099733353038802970355718221088259886925518970281655634779851495550264110452025361079238655051609110357880450805087197804035613307707314768911650131971835865731706270390379379832722335057330470...

output:

205053522239938674591892402487189053710615058618263744683481312111488658741992465320941967150680269368386256900266646961197029644281778911740113074481029718344365220148504449735889547974638920761344948390889642119549194912802195964386692292685231088349868028164134268293729609620620167277664942669529...

result:

ok answer is '205053522239938674591892402487...4895693158694032335924691582580'

Test #12:

score: 0
Accepted
time: 24ms
memory: 22172kb

input:

740396512715746854480688476727726843695909844190398984187893683516689175082139997856915168192558523514785642438089549764358594098561796813209038321522889191781035343854374929109665898552729746770608711636305055090924461862639090335815510632703670463147194228154033606862279586041022594067305712355803...

output:

259603487284253145519311523272273156304090155809601015812106316483310824917860002143084831807441476485214357561910450235641405901438203186790961678477110808218964656145625070890334101447270253229391288363694944909075538137360909664184489367296329536852805771845966393137720413958977405932694287644196...

result:

ok answer is '259603487284253145519311523272...7124298880143408010404228204895'

Test #13:

score: 0
Accepted
time: 35ms
memory: 22124kb

input:

808080808080808080808080808080808080808080808080808080808080808080808080808080808080808080808080808080808080808080808080808080808080808080808080808080808080808080808080808080808080808080808080808080808080808080808080808080808080808080808080808080808080808080808080808080808080808080808080808080808080...

output:

191919191919191919191919191919191919191919191919191919191919191919191919191919191919191919191919191919191919191919191919191919191919191919191919191919191919191919191919191919191919191919191919191919191919191919191919191919191919191919191919191919191919191919191919191919191919191919191919191919191919...

result:

ok answer is '191919191919191919191919191919...9191919191919191919191919191920'

Test #14:

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

input:

999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999...

output:

1

result:

ok answer is '1'

Test #15:

score: 0
Accepted
time: 32ms
memory: 22944kb

input:

888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888...

output:

111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111...

result:

ok answer is '111111111111111111111111111111...1111111111111111111111111111112'

Test #16:

score: 0
Accepted
time: 35ms
memory: 22048kb

input:

499999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999...

output:

499999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999...

result:

ok answer is '499999999999999999999999999999...9999999999999999999999999999999'

Test #17:

score: 0
Accepted
time: 23ms
memory: 21244kb

input:

902851346436306806616375942396607826120232155242259147614243592903405735290837981154314613604373937058180635157768204138128396693345023355887820571704408856138693881765209464570723015717187118417699724996521322468835282812828545349457610944807873712140962669646920063042802116551616341958682221180684...

output:

739784808063119079929960519131554991813736147608454624748722101820388330144313273774081346945197605998068619643008000320015228364440867297627844532995103260191004283851259488125663821507594499196247233749377082143689851535156330319615505969268510443807604553524147479720718432743772029026906290480988...

result:

ok answer is '739784808063119079929960519131...1948627624188898000206620879303'

Test #18:

score: 0
Accepted
time: 27ms
memory: 22552kb

input:

724416096404218447265833382721297139425723348230646412938535112399662200961459489276744159193709343615237043403451777684608176033864123303353042148426141106174503987074111702253415957879317805779143259309953292187561544285879213401013240932738394155151275424316854703682327362480740497418303833476481...

output:

275583903595781552734166617278702860574276651769353587061464887600337799038540510723255840806290656384762956596548222315391823966135876696646957851573858893825496012925888297746584042120682194220856740690046707812438455714120786598986759067261605844848724575683145296317672637519259502581696166523518...

result:

ok answer is '275583903595781552734166617278...8872930707584800540407644105638'

Test #19:

score: 0
Accepted
time: 36ms
memory: 22916kb

input:

179760883913929098769751954947190783986510762079451401291657475628833258870415316784826579026164324281062020081021320517742313824799906611937368746321612306269758496471784982997262378087781498524472377305471180347632989650011243499867679056925218306140508787728196557041840793032875464254908876021669...

output:

202391160860709012302480450528092160134892379205485987083425243711667411295846832151734209738356757189379799189786794822576861752000933880626312536783876937302415035282150170027376219122185014755276226945288196523670103499887565001323209430747816938594912122718034429581592069671245357450911239783305...

result:

ok answer is '202391160860709012302480450528...2823656215559711050462000001286'

Test #20:

score: 0
Accepted
time: 28ms
memory: 21876kb

input:

694093295978385763996081646122651163487393563403375307120640726515101625170981544132833099306255215328986417862623494481857751894930538664304406593098107350723363635953635761495109280467562145123198911580622745275722840557806514156432129827761280709147879094131413817732889425551527261432195522728058...

output:

255769660772460029135659150462029009323862269154134965970617506744888571963168440708845854207631866982569513435894446504364418923339414859467991484536976751318428793008155206466142281148699553779149059558262299962485591410811078329484901571300035768990820396518084796670337233215816256442433385117841...

result:

ok answer is '255769660772460029135659150462...5240882786975575043401117211469'

Test #21:

score: 0
Accepted
time: 19ms
memory: 22416kb

input:

300681870704322241560104970320057811567211737552516811385136323064072671173825819427397761947835599467617616151523159779966244586152970280628373138993914850714409848595061132786328706497489992388484505984334528900604134964071443214035814375461628216063519758155475552005548598916806141612427038578006...

output:

245470701274362774449400345544121088380094571024237326765419310035541831084665407865334639554935227551147676469232950570285818569364395955422076452513852795266969401671952897250009875595788582424670890141940295697590000618374944180311423441095906635772223869242769402714599365582728097188947527241436...

result:

ok answer is '245470701274362774449400345544...4786420933984638221599280514231'