QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#133885 | #6257. Efficient Exchange | KhNURE_KIVI# | AC ✓ | 1ms | 3584kb | C++14 | 3.2kb | 2023-08-02 16:29:02 | 2023-08-02 16:29:03 |
Judging History
answer
//#pragma GCC optimize("Ofast", "unroll-loops")
//#pragma GCC target("sse", "sse2", "sse3", "ssse3", "sse4")
#ifdef LOCAL
#include <iostream>
#include <cmath>
#include <algorithm>
#include <stdio.h>
#include <cstdint>
#include <cstring>
#include <string>
#include <cstdlib>
#include <vector>
#include <bitset>
#include <map>
#include <queue>
#include <ctime>
#include <stack>
#include <set>
#include <list>
#include <random>
#include <deque>
#include <functional>
#include <iomanip>
#include <sstream>
#include <fstream>
#include <complex>
#include <numeric>
#include <cassert>
#include <array>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <thread>
#else
#include <bits/stdc++.h>
#endif
#define all(a) a.begin(),a.end()
#define len(a) (int)(a.size())
#define mp make_pair
#define pb push_back
#define fir first
#define sec second
#define fi first
#define se second
using namespace std;
typedef pair<int, int> pii;
typedef long long ll;
typedef long double ld;
template<typename T>
inline bool umin(T &a, T b) {
if (b < a) {
a = b;
return true;
}
return false;
}
template<typename T>
inline bool umax(T &a, T b) {
if (a < b) {
a = b;
return true;
}
return false;
}
#ifdef LOCAL
#define D for (bool _FLAG = true; _FLAG; _FLAG = false)
#define LOG(...) print(#__VA_ARGS__" ::", __VA_ARGS__) << endl
template <class ...Ts> auto &print(Ts ...ts) { return ((cerr << ts << " "), ...); }
#else
#define D while (false)
#define LOG(...)
#endif // LOCAL
const int max_n = -1, inf = 1000111222;
int main() {
// freopen("input.txt", "r", stdin);
// freopen("output.txt", "w", stdout);
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
string s;
cin >> s;
reverse(all(s));
s.pb('0');
s.pb('0');
reverse(all(s));
int n = len(s);
int dp[2][2] = {};
for (int i = 0; i < 2; i++) {
dp[i][0] = inf;
dp[i][1] = inf;
}
dp[0][1] = 0;
for (int i = n - 1; i >= 0; i--) {
int cur = s[i] - '0';
int new_dp[2][2] = {};
for (int i = 0; i < 2; i++) {
new_dp[i][0] = inf;
new_dp[i][1] = inf;
}
for (int carry = 0; carry < 2; carry++) {
for (int f = 0; f < 2; f++) {
for (int val = 0; val < 10; val++) {
int t = f;
if (val > cur) {
t = 1;
}
else if (val < cur) {
t = 0;
}
int cur_val = val - cur - carry;
int need = 0;
if (cur_val < 0) {
need = 1;
cur_val += 10;
}
umin(new_dp[need][t], dp[carry][f] + val + cur_val);
}
}
}
for (int i = 0; i < 2; i++) {
dp[i][0] = new_dp[i][0];
dp[i][1] = new_dp[i][1];
new_dp[i][0] = inf;
new_dp[i][1] = inf;
}
}
cout << dp[0][1] << '\n';
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 1ms
memory: 3456kb
input:
83
output:
6
result:
ok single line: '6'
Test #2:
score: 0
Accepted
time: 1ms
memory: 3564kb
input:
13
output:
4
result:
ok single line: '4'
Test #3:
score: 0
Accepted
time: 1ms
memory: 3452kb
input:
0
output:
0
result:
ok single line: '0'
Test #4:
score: 0
Accepted
time: 1ms
memory: 3464kb
input:
12345678987654321
output:
42
result:
ok single line: '42'
Test #5:
score: 0
Accepted
time: 1ms
memory: 3528kb
input:
1
output:
1
result:
ok single line: '1'
Test #6:
score: 0
Accepted
time: 1ms
memory: 3540kb
input:
108894478469214466804158556038509473912228070531930682335592810379690071992846446138400855834536144291684432969861435324866089578025171848195442401602361161260026599515983657327709498488895075795438278518721851530339458103065105649832422088699047412786278455363479689485262210227415931822805287251225...
output:
1971
result:
ok single line: '1971'
Test #7:
score: 0
Accepted
time: 0ms
memory: 3520kb
input:
155657272188452258350034380622506009947304059264052627243071743747532300522919572993515854882869064965994030247295293351158207123830911435744207850943972297748665270071798324245389096610864530828634938222945980818832206282110768734660809669941759092258710662899974508400631678381569312965707983946432
output:
727
result:
ok single line: '727'
Test #8:
score: 0
Accepted
time: 1ms
memory: 3524kb
input:
184293602707127482667135655938747789712189649148930742992933133452462900071840556139777075958677006206950802685360638631097097555913098361665555519075109818871319874846199491028725782220390691671918986736126038811707738246531755860287041942198563406450643429071794580502357738722260280221637052566622...
output:
1388
result:
ok single line: '1388'
Test #9:
score: 0
Accepted
time: 0ms
memory: 3452kb
input:
10
output:
1
result:
ok single line: '1'
Test #10:
score: 0
Accepted
time: 1ms
memory: 3520kb
input:
100
output:
1
result:
ok single line: '1'
Test #11:
score: 0
Accepted
time: 1ms
memory: 3476kb
input:
999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999...
output:
2
result:
ok single line: '2'
Test #12:
score: 0
Accepted
time: 1ms
memory: 3500kb
input:
927921025314975768131904512726117652463595287536883360313991521661524926483956016479890394072472783724117472774060584557954348768216323088030199807746884216789632406284551408158333612255548346529968167404891207258991365367362134354507171299646862083803338315300776525592155222220598847462648664077391...
output:
2531
result:
ok single line: '2531'
Test #13:
score: 0
Accepted
time: 0ms
memory: 3572kb
input:
990000000900999999099999909090090900099009999009090000990909099099999909999009009099900099900900090099009900099000099900909009090009099909999990009900009900000900090990990099009990099900990099000990009000090900999099999990000099009009990009900009099999090009990009009000090099009900909099990999099009...
output:
472
result:
ok single line: '472'
Test #14:
score: 0
Accepted
time: 1ms
memory: 3476kb
input:
110011001010001111100111111010101010001100100111000001101001000000011111010011100011111111111111001111100001000011010011111111011010111111010101111110101100101110011101101001110001111100001010011110100100001101010110010100010100100110010101100110111000111010100011011100011110101010110101011100000011...
output:
520
result:
ok single line: '520'
Test #15:
score: 0
Accepted
time: 1ms
memory: 3476kb
input:
444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444...
output:
4000
result:
ok single line: '4000'
Test #16:
score: 0
Accepted
time: 1ms
memory: 3568kb
input:
555445555544545554454445544455444555445545444444555444454544444444554455455445455555554555555455454555554444444445555555555544445455545444444554445444444544554445554454445544454454544554544454445544445445555544444554454544545554545445455444555444444545544545544444544454454454554454444555445445445444...
output:
4317
result:
ok single line: '4317'
Test #17:
score: 0
Accepted
time: 1ms
memory: 3460kb
input:
555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555...
output:
4002
result:
ok single line: '4002'
Test #18:
score: 0
Accepted
time: 0ms
memory: 3448kb
input:
10289
output:
6
result:
ok single line: '6'
Test #19:
score: 0
Accepted
time: 1ms
memory: 3492kb
input:
4477533878
output:
30
result:
ok single line: '30'
Test #20:
score: 0
Accepted
time: 1ms
memory: 3456kb
input:
9191119911
output:
12
result:
ok single line: '12'
Test #21:
score: 0
Accepted
time: 0ms
memory: 3464kb
input:
4544545545
output:
45
result:
ok single line: '45'
Test #22:
score: 0
Accepted
time: 0ms
memory: 3468kb
input:
18299
output:
8
result:
ok single line: '8'
Test #23:
score: 0
Accepted
time: 1ms
memory: 3532kb
input:
1920
output:
5
result:
ok single line: '5'
Test #24:
score: 0
Accepted
time: 1ms
memory: 3536kb
input:
2
output:
2
result:
ok single line: '2'
Test #25:
score: 0
Accepted
time: 1ms
memory: 3460kb
input:
3
output:
3
result:
ok single line: '3'
Test #26:
score: 0
Accepted
time: 1ms
memory: 3492kb
input:
3601826089394934547881508232828452773858944039831489287992733143785136405727111959516289301182688004
output:
239
result:
ok single line: '239'
Test #27:
score: 0
Accepted
time: 1ms
memory: 3564kb
input:
4
output:
4
result:
ok single line: '4'
Test #28:
score: 0
Accepted
time: 1ms
memory: 3500kb
input:
424475839223098881451701291874221767524939363838369849117771957128318512749513432010678005280497527077017899932271898215656477666400407938133443370979649525628962814949683408037996807631208896219300316204277657292147893960426878912831998492826687120945076725188722344056781314834755472046373126297943...
output:
2448
result:
ok single line: '2448'
Test #29:
score: 0
Accepted
time: 0ms
memory: 3464kb
input:
44
output:
8
result:
ok single line: '8'
Test #30:
score: 0
Accepted
time: 1ms
memory: 3488kb
input:
45
output:
9
result:
ok single line: '9'
Test #31:
score: 0
Accepted
time: 1ms
memory: 3472kb
input:
454545454545454545454545454545454545454545454545454545454545454545454545454545454545454545454545454545454545454545454545454545454545454545454545454545454545454545454545454545454545454545454545454545454545454545454545454545454545454545454545454545454545454545454545454545454545454545454545454545454545...
output:
4500
result:
ok single line: '4500'
Test #32:
score: 0
Accepted
time: 1ms
memory: 3456kb
input:
489201
output:
10
result:
ok single line: '10'
Test #33:
score: 0
Accepted
time: 1ms
memory: 3448kb
input:
5
output:
5
result:
ok single line: '5'
Test #34:
score: 0
Accepted
time: 1ms
memory: 3492kb
input:
585769671396938029525421625659164648715839715491356508606854385199925683827582042246698358391826413274466179915350417956880188533046212518827221637732426676267875758978853565444052250327606146707002623809699725723644717352564729074731882563136532623250182183375510620129543308817520283802270018811337...
output:
1019
result:
ok single line: '1019'
Test #35:
score: 0
Accepted
time: 1ms
memory: 3448kb
input:
54
output:
9
result:
ok single line: '9'
Test #36:
score: 0
Accepted
time: 1ms
memory: 3468kb
input:
544
output:
13
result:
ok single line: '13'
Test #37:
score: 0
Accepted
time: 1ms
memory: 3448kb
input:
545
output:
14
result:
ok single line: '14'
Test #38:
score: 0
Accepted
time: 0ms
memory: 3512kb
input:
546
output:
14
result:
ok single line: '14'
Test #39:
score: 0
Accepted
time: 1ms
memory: 3472kb
input:
545454545454545454545454545454545454545454545454545454545454545454545454545454545454545454545454545454545454545454545454545454545454545454545454545454545454545454545454545454545454545454545454545454545454545454545454545454545454545454545454545454545454545454545454545454545454545454545454545454545454...
output:
4500
result:
ok single line: '4500'
Test #40:
score: 0
Accepted
time: 1ms
memory: 3580kb
input:
55
output:
10
result:
ok single line: '10'
Test #41:
score: 0
Accepted
time: 1ms
memory: 3468kb
input:
6
output:
5
result:
ok single line: '5'
Test #42:
score: 0
Accepted
time: 0ms
memory: 3564kb
input:
666666666666666666666666666666666666
output:
110
result:
ok single line: '110'
Test #43:
score: 0
Accepted
time: 1ms
memory: 3448kb
input:
654
output:
13
result:
ok single line: '13'
Test #44:
score: 0
Accepted
time: 1ms
memory: 3496kb
input:
714147856978842163481106976197602730881244144727775565789534388473913021020249356165516251075850782355553103002506915961964164043615288946483173929145474708286773801296539465227418354209023888787344952179075219532180829667393187297408571204137268380638609338540986504182593763352579628081137822660425...
output:
1222
result:
ok single line: '1222'
Test #45:
score: 0
Accepted
time: 1ms
memory: 3584kb
input:
733261168214233103490160050307230634591506434031875719027622026954095990688581514098773384226313576605242629762631026702482830809158576241596304598386148234975548453867128195272650349419049807588496358825581846368782083021944754011655475567898548786508023056288990666363586242325430748878768245584658...
output:
1743
result:
ok single line: '1743'
Test #46:
score: 0
Accepted
time: 1ms
memory: 3528kb
input:
77777777777777777777777
output:
48
result:
ok single line: '48'
Test #47:
score: 0
Accepted
time: 0ms
memory: 3448kb
input:
8
output:
3
result:
ok single line: '3'
Test #48:
score: 0
Accepted
time: 0ms
memory: 3524kb
input:
855468224966685726201412469649855594862031249642826453441030749753190770029027077509351906629906820496341079807303161556527377590613374751926911086930997277643059313961383006883616535973231062558864893572663339728649813393002875962509015650200723176211932429960723096921226718375783791714897546914561...
output:
2195
result:
ok single line: '2195'
Test #49:
score: 0
Accepted
time: 1ms
memory: 3580kb
input:
9
output:
2
result:
ok single line: '2'
Test #50:
score: 0
Accepted
time: 1ms
memory: 3520kb
input:
94624813447863763071368974578344920977065967164495424788607850540371893800410826359650060836422974595121406401329325788029685604776998307383773972107524107122147356950252110491718219537949058540996897
output:
481
result:
ok single line: '481'
Test #51:
score: 0
Accepted
time: 1ms
memory: 3520kb
input:
9999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999998
output:
3
result:
ok single line: '3'
Test #52:
score: 0
Accepted
time: 1ms
memory: 3460kb
input:
944
output:
10
result:
ok single line: '10'
Test #53:
score: 0
Accepted
time: 1ms
memory: 3452kb
input:
946
output:
10
result:
ok single line: '10'
Test #54:
score: 0
Accepted
time: 1ms
memory: 3452kb
input:
971988577901054135
output:
36
result:
ok single line: '36'
Test #55:
score: 0
Accepted
time: 0ms
memory: 3456kb
input:
12725342537225220
output:
48
result:
ok single line: '48'
Test #56:
score: 0
Accepted
time: 1ms
memory: 3448kb
input:
497373703586641160
output:
49
result:
ok single line: '49'
Test #57:
score: 0
Accepted
time: 0ms
memory: 3484kb
input:
106
output:
6
result:
ok single line: '6'
Test #58:
score: 0
Accepted
time: 1ms
memory: 3532kb
input:
531
output:
9
result:
ok single line: '9'
Test #59:
score: 0
Accepted
time: 1ms
memory: 3580kb
input:
476
output:
11
result:
ok single line: '11'
Test #60:
score: 0
Accepted
time: 1ms
memory: 3576kb
input:
12057
output:
11
result:
ok single line: '11'
Test #61:
score: 0
Accepted
time: 1ms
memory: 3472kb
input:
44165
output:
18
result:
ok single line: '18'
Test #62:
score: 0
Accepted
time: 1ms
memory: 3512kb
input:
50132
output:
11
result:
ok single line: '11'