QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#640639 | #6257. Efficient Exchange | BaBamBa# | AC ✓ | 0ms | 3856kb | C++17 | 903b | 2024-10-14 14:56:20 | 2024-10-14 14:56:20 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
string s;
cin >> s;
ll ans = 0, up = 0;
reverse(s.begin(), s.end());
s += '0';
for (int i = 0; i < s.length() - 1; i++)
{
if (s[i] - '0' + up < 5)
{
ans += s[i] - '0' + up;
up = 0;
}
else if (s[i] - '0' + up == 5)
{
if (s[i + 1] >= '5')
{
ans += 10 - s[i] + '0' - up;
up = 1;
}
else
{
ans += s[i] - '0' + up;
up = 0;
}
}
else
{
ans += 10 - s[i] + '0' - up;
up = 1;
}
}
ans += up;
cout << ans << "\n";
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 3616kb
input:
83
output:
6
result:
ok single line: '6'
Test #2:
score: 0
Accepted
time: 0ms
memory: 3548kb
input:
13
output:
4
result:
ok single line: '4'
Test #3:
score: 0
Accepted
time: 0ms
memory: 3500kb
input:
0
output:
0
result:
ok single line: '0'
Test #4:
score: 0
Accepted
time: 0ms
memory: 3648kb
input:
12345678987654321
output:
42
result:
ok single line: '42'
Test #5:
score: 0
Accepted
time: 0ms
memory: 3616kb
input:
1
output:
1
result:
ok single line: '1'
Test #6:
score: 0
Accepted
time: 0ms
memory: 3856kb
input:
108894478469214466804158556038509473912228070531930682335592810379690071992846446138400855834536144291684432969861435324866089578025171848195442401602361161260026599515983657327709498488895075795438278518721851530339458103065105649832422088699047412786278455363479689485262210227415931822805287251225...
output:
1971
result:
ok single line: '1971'
Test #7:
score: 0
Accepted
time: 0ms
memory: 3500kb
input:
155657272188452258350034380622506009947304059264052627243071743747532300522919572993515854882869064965994030247295293351158207123830911435744207850943972297748665270071798324245389096610864530828634938222945980818832206282110768734660809669941759092258710662899974508400631678381569312965707983946432
output:
727
result:
ok single line: '727'
Test #8:
score: 0
Accepted
time: 0ms
memory: 3552kb
input:
184293602707127482667135655938747789712189649148930742992933133452462900071840556139777075958677006206950802685360638631097097555913098361665555519075109818871319874846199491028725782220390691671918986736126038811707738246531755860287041942198563406450643429071794580502357738722260280221637052566622...
output:
1388
result:
ok single line: '1388'
Test #9:
score: 0
Accepted
time: 0ms
memory: 3848kb
input:
10
output:
1
result:
ok single line: '1'
Test #10:
score: 0
Accepted
time: 0ms
memory: 3552kb
input:
100
output:
1
result:
ok single line: '1'
Test #11:
score: 0
Accepted
time: 0ms
memory: 3612kb
input:
999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999...
output:
2
result:
ok single line: '2'
Test #12:
score: 0
Accepted
time: 0ms
memory: 3840kb
input:
927921025314975768131904512726117652463595287536883360313991521661524926483956016479890394072472783724117472774060584557954348768216323088030199807746884216789632406284551408158333612255548346529968167404891207258991365367362134354507171299646862083803338315300776525592155222220598847462648664077391...
output:
2531
result:
ok single line: '2531'
Test #13:
score: 0
Accepted
time: 0ms
memory: 3548kb
input:
990000000900999999099999909090090900099009999009090000990909099099999909999009009099900099900900090099009900099000099900909009090009099909999990009900009900000900090990990099009990099900990099000990009000090900999099999990000099009009990009900009099999090009990009009000090099009900909099990999099009...
output:
472
result:
ok single line: '472'
Test #14:
score: 0
Accepted
time: 0ms
memory: 3776kb
input:
110011001010001111100111111010101010001100100111000001101001000000011111010011100011111111111111001111100001000011010011111111011010111111010101111110101100101110011101101001110001111100001010011110100100001101010110010100010100100110010101100110111000111010100011011100011110101010110101011100000011...
output:
520
result:
ok single line: '520'
Test #15:
score: 0
Accepted
time: 0ms
memory: 3544kb
input:
444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444...
output:
4000
result:
ok single line: '4000'
Test #16:
score: 0
Accepted
time: 0ms
memory: 3584kb
input:
555445555544545554454445544455444555445545444444555444454544444444554455455445455555554555555455454555554444444445555555555544445455545444444554445444444544554445554454445544454454544554544454445544445445555544444554454544545554545445455444555444444545544545544444544454454454554454444555445445445444...
output:
4317
result:
ok single line: '4317'
Test #17:
score: 0
Accepted
time: 0ms
memory: 3616kb
input:
555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555...
output:
4002
result:
ok single line: '4002'
Test #18:
score: 0
Accepted
time: 0ms
memory: 3552kb
input:
10289
output:
6
result:
ok single line: '6'
Test #19:
score: 0
Accepted
time: 0ms
memory: 3836kb
input:
4477533878
output:
30
result:
ok single line: '30'
Test #20:
score: 0
Accepted
time: 0ms
memory: 3592kb
input:
9191119911
output:
12
result:
ok single line: '12'
Test #21:
score: 0
Accepted
time: 0ms
memory: 3556kb
input:
4544545545
output:
45
result:
ok single line: '45'
Test #22:
score: 0
Accepted
time: 0ms
memory: 3780kb
input:
18299
output:
8
result:
ok single line: '8'
Test #23:
score: 0
Accepted
time: 0ms
memory: 3852kb
input:
1920
output:
5
result:
ok single line: '5'
Test #24:
score: 0
Accepted
time: 0ms
memory: 3808kb
input:
2
output:
2
result:
ok single line: '2'
Test #25:
score: 0
Accepted
time: 0ms
memory: 3552kb
input:
3
output:
3
result:
ok single line: '3'
Test #26:
score: 0
Accepted
time: 0ms
memory: 3552kb
input:
3601826089394934547881508232828452773858944039831489287992733143785136405727111959516289301182688004
output:
239
result:
ok single line: '239'
Test #27:
score: 0
Accepted
time: 0ms
memory: 3840kb
input:
4
output:
4
result:
ok single line: '4'
Test #28:
score: 0
Accepted
time: 0ms
memory: 3776kb
input:
424475839223098881451701291874221767524939363838369849117771957128318512749513432010678005280497527077017899932271898215656477666400407938133443370979649525628962814949683408037996807631208896219300316204277657292147893960426878912831998492826687120945076725188722344056781314834755472046373126297943...
output:
2448
result:
ok single line: '2448'
Test #29:
score: 0
Accepted
time: 0ms
memory: 3616kb
input:
44
output:
8
result:
ok single line: '8'
Test #30:
score: 0
Accepted
time: 0ms
memory: 3548kb
input:
45
output:
9
result:
ok single line: '9'
Test #31:
score: 0
Accepted
time: 0ms
memory: 3500kb
input:
454545454545454545454545454545454545454545454545454545454545454545454545454545454545454545454545454545454545454545454545454545454545454545454545454545454545454545454545454545454545454545454545454545454545454545454545454545454545454545454545454545454545454545454545454545454545454545454545454545454545...
output:
4500
result:
ok single line: '4500'
Test #32:
score: 0
Accepted
time: 0ms
memory: 3848kb
input:
489201
output:
10
result:
ok single line: '10'
Test #33:
score: 0
Accepted
time: 0ms
memory: 3612kb
input:
5
output:
5
result:
ok single line: '5'
Test #34:
score: 0
Accepted
time: 0ms
memory: 3496kb
input:
585769671396938029525421625659164648715839715491356508606854385199925683827582042246698358391826413274466179915350417956880188533046212518827221637732426676267875758978853565444052250327606146707002623809699725723644717352564729074731882563136532623250182183375510620129543308817520283802270018811337...
output:
1019
result:
ok single line: '1019'
Test #35:
score: 0
Accepted
time: 0ms
memory: 3776kb
input:
54
output:
9
result:
ok single line: '9'
Test #36:
score: 0
Accepted
time: 0ms
memory: 3544kb
input:
544
output:
13
result:
ok single line: '13'
Test #37:
score: 0
Accepted
time: 0ms
memory: 3812kb
input:
545
output:
14
result:
ok single line: '14'
Test #38:
score: 0
Accepted
time: 0ms
memory: 3612kb
input:
546
output:
14
result:
ok single line: '14'
Test #39:
score: 0
Accepted
time: 0ms
memory: 3856kb
input:
545454545454545454545454545454545454545454545454545454545454545454545454545454545454545454545454545454545454545454545454545454545454545454545454545454545454545454545454545454545454545454545454545454545454545454545454545454545454545454545454545454545454545454545454545454545454545454545454545454545454...
output:
4500
result:
ok single line: '4500'
Test #40:
score: 0
Accepted
time: 0ms
memory: 3584kb
input:
55
output:
10
result:
ok single line: '10'
Test #41:
score: 0
Accepted
time: 0ms
memory: 3556kb
input:
6
output:
5
result:
ok single line: '5'
Test #42:
score: 0
Accepted
time: 0ms
memory: 3500kb
input:
666666666666666666666666666666666666
output:
110
result:
ok single line: '110'
Test #43:
score: 0
Accepted
time: 0ms
memory: 3612kb
input:
654
output:
13
result:
ok single line: '13'
Test #44:
score: 0
Accepted
time: 0ms
memory: 3552kb
input:
714147856978842163481106976197602730881244144727775565789534388473913021020249356165516251075850782355553103002506915961964164043615288946483173929145474708286773801296539465227418354209023888787344952179075219532180829667393187297408571204137268380638609338540986504182593763352579628081137822660425...
output:
1222
result:
ok single line: '1222'
Test #45:
score: 0
Accepted
time: 0ms
memory: 3616kb
input:
733261168214233103490160050307230634591506434031875719027622026954095990688581514098773384226313576605242629762631026702482830809158576241596304598386148234975548453867128195272650349419049807588496358825581846368782083021944754011655475567898548786508023056288990666363586242325430748878768245584658...
output:
1743
result:
ok single line: '1743'
Test #46:
score: 0
Accepted
time: 0ms
memory: 3556kb
input:
77777777777777777777777
output:
48
result:
ok single line: '48'
Test #47:
score: 0
Accepted
time: 0ms
memory: 3652kb
input:
8
output:
3
result:
ok single line: '3'
Test #48:
score: 0
Accepted
time: 0ms
memory: 3608kb
input:
855468224966685726201412469649855594862031249642826453441030749753190770029027077509351906629906820496341079807303161556527377590613374751926911086930997277643059313961383006883616535973231062558864893572663339728649813393002875962509015650200723176211932429960723096921226718375783791714897546914561...
output:
2195
result:
ok single line: '2195'
Test #49:
score: 0
Accepted
time: 0ms
memory: 3840kb
input:
9
output:
2
result:
ok single line: '2'
Test #50:
score: 0
Accepted
time: 0ms
memory: 3772kb
input:
94624813447863763071368974578344920977065967164495424788607850540371893800410826359650060836422974595121406401329325788029685604776998307383773972107524107122147356950252110491718219537949058540996897
output:
481
result:
ok single line: '481'
Test #51:
score: 0
Accepted
time: 0ms
memory: 3808kb
input:
9999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999998
output:
3
result:
ok single line: '3'
Test #52:
score: 0
Accepted
time: 0ms
memory: 3552kb
input:
944
output:
10
result:
ok single line: '10'
Test #53:
score: 0
Accepted
time: 0ms
memory: 3616kb
input:
946
output:
10
result:
ok single line: '10'
Test #54:
score: 0
Accepted
time: 0ms
memory: 3612kb
input:
971988577901054135
output:
36
result:
ok single line: '36'
Test #55:
score: 0
Accepted
time: 0ms
memory: 3556kb
input:
12725342537225220
output:
48
result:
ok single line: '48'
Test #56:
score: 0
Accepted
time: 0ms
memory: 3808kb
input:
497373703586641160
output:
49
result:
ok single line: '49'
Test #57:
score: 0
Accepted
time: 0ms
memory: 3616kb
input:
106
output:
6
result:
ok single line: '6'
Test #58:
score: 0
Accepted
time: 0ms
memory: 3608kb
input:
531
output:
9
result:
ok single line: '9'
Test #59:
score: 0
Accepted
time: 0ms
memory: 3856kb
input:
476
output:
11
result:
ok single line: '11'
Test #60:
score: 0
Accepted
time: 0ms
memory: 3548kb
input:
12057
output:
11
result:
ok single line: '11'
Test #61:
score: 0
Accepted
time: 0ms
memory: 3552kb
input:
44165
output:
18
result:
ok single line: '18'
Test #62:
score: 0
Accepted
time: 0ms
memory: 3608kb
input:
50132
output:
11
result:
ok single line: '11'