QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#744610 | #6300. Best Carry Player 2 | wuya# | TL | 0ms | 3608kb | C++17 | 2.3kb | 2024-11-13 22:37:10 | 2024-11-13 22:37:11 |
Judging History
answer
// #pragma GCC optimize(2)
#include <bits/stdc++.h>
using namespace std;
#define IOS \
ios::sync_with_stdio(false); \
cin.tie(0); \
cout.tie(0);
#define pb push_back
#define st first
#define nd second
#define PII pair<ll, ll>
#define D(x, y) cout << x << "=" << y << endl;
#define fcout(x, n) cout << fixed << setprecision(x) << n << endl;
#define rep(i, a, b) for (int i = a; i < b; i++)
#define rep2(i, a, b) for (int i = a; i >= b; i--)
// #define int long long
typedef long long ll;
typedef unsigned long long ull;
const ll inf = 0x3f3f3f3f;
const int N = 2e5 + 10;
const int M = 1e9 + 7;
ll a[20], b[20], c[20];
ll n, k;
ll ans = 0;
void dfs(ll x, ll sum, bool jw, ll num)
{
if (num == k && jw == 0)
{
ans = min(ans, sum);
return;
}
if (num > k)
return;
if (x > 18)
return;
if (jw && a[x] == 9)
dfs(x + 1, sum, 1, num + 1);
else if (jw && a[x] != 9)
{
dfs(x + 1, sum, 0, num);
dfs(x + 1, sum + b[x], 1, num + 1);
}
else
{
if (a[x] == 0)
dfs(x + 1, sum, 0, num);
else
{
dfs(x + 1, sum + c[x], 1, num + 1);
dfs(x + 1, sum, 0, num);
}
}
}
void solve()
{
ll x, y;
cin >> x >> k;
ll ttt = 1;
if (k == 0)
{
while (1)
{
ll i = x % 10;
if (i != 9)
{
cout << ttt << endl;
return;
}
x /= 10;
ttt *= 10;
}
}
ll num = 0;
ans = LLONG_MAX;
while (x % 10 == 0)
{
x /= 10;
num++;
}
ll t = x, tt = 1;
for (ll i = 0; i <= 18; i++)
{
ll u = t % 10;
a[i] = u;
b[i] = (9 - u) * tt;
c[i] = (10 - u) * tt;
tt *= 10;
t /= 10;
}
// for(ll i = 0; i <= 18; i++)
// cout << b[i] << endl;
dfs(0, 0, 0, 0);
cout << ans;
for (ll i = 1; i <= num; i++)
cout << 0;
cout << '\n';
}
signed main()
{
IOS
// freopen("../.vscode/io/in.txt","r",stdin),freopen("../.vscode/io/out.txt","w",stdout);
ll T = 1;
cin >> T;
while (T--)
solve();
}
詳細信息
Test #1:
score: 100
Accepted
time: 0ms
memory: 3544kb
input:
4 12345678 0 12345678 5 12345678 18 990099 5
output:
1 54322 999999999987654322 9910
result:
ok 4 lines
Test #2:
score: 0
Accepted
time: 0ms
memory: 3608kb
input:
21 999990000099999 0 999990000099999 1 999990000099999 2 999990000099999 3 999990000099999 4 999990000099999 5 999990000099999 6 999990000099999 7 999990000099999 8 999990000099999 9 999990000099999 10 999990000099999 11 999990000099999 12 999990000099999 13 999990000099999 14 999990000099999 15 999...
output:
100000 10000 1000 100 10 1 900001 9900001 99900001 999900001 10000000001 9999910000 9999901000 9999900100 9999900010 9999900001 9000009999900001 99000009999900001 999000009999900001 99999999999999999900000000000000000 1000000000000000000
result:
ok 21 lines
Test #3:
score: -100
Time Limit Exceeded
input:
100000 119111011091190000 10 1911011191011999 16 110099199000119 0 19009911191091011 13 199090909919000900 17 19009010011919110 5 90910190019900091 18 10911100000101111 1 110090011101119990 4 100909999119090000 12 90901119109011100 2 111010119991090101 4 900991019109199009 5 100919919990991119 8 911...
output:
88988908810000 8088988808988001 10 88808908989 9800909090080999100 80890 909089809980099909 9 80010 9090000880910000 8900 9909 991 9008900 8880880090 8080090801 8009900808909899 80880898981 909 8800909 99988889901 89908888089 980908890980099000 100 9889801 81 908890008099900891 880990801 9998099 890...