QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#253554 | #6300. Best Carry Player 2 | SATSKY | WA | 14ms | 3624kb | C++20 | 1.5kb | 2023-11-17 08:32:39 | 2023-11-17 08:32:39 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;using ll=long long;const ll inf=3e18;
int o,o2,tc;
struct S
{
vector<vector<vector<ll>>>dp;
void solve()
{
//cout<<100000000000000000ll-90098080909000810ll<<'\n';
int c0=0,di[19];tc++;
ll x,k;cin>>x>>k;
if(o)
{
if(tc==81)cout<<x<<' '<<k<<'\n';return;
}
while(x%10==0)x/=10,c0++;
if(k==18)
{
ll bs=1;for(int i=1;i<=18;i++)bs*=10;cout<<bs-x;
while(c0--)cout<<'0';cout<<'\n';return;
}
else if(k==0)
{
if(c0){cout<<"1\n";return;}ll res=1;
while(x%10==9)x/=10,res*=10;cout<<res<<'\n';return;
}
dp.resize(20,vector<vector<ll>>(20,vector<ll>(2,inf)));
dp[0][0][0]=0;ll bas=1;
for(int i=1;i<=18;i++)di[i]=x%10,x/=10;
for(int i=1;i<=18;i++,bas*=10)
{
for(int j=0;j<=18;j++)
{
dp[i][j][0]=min(dp[i][j][0],dp[i-1][j][0]);
if(di[i]!=9)dp[i][j][0]=min(dp[i][j][0],dp[i-1][j][1]);
dp[i][j+1][1]=min(dp[i][j+1][1],dp[i-1][j][1]+bas*(9-di[i]));
if(di[i]!=0)dp[i][j+1][1]=min(dp[i][j+1][1],dp[i-1][j][0]+bas*(10-di[i]));
//cout<<"now"<<i<<"over"<<j<<"L"<<0<<":"<<dp[i][j][0]<<'\n';
//cout<<"now"<<i<<"over"<<j<<"L"<<1<<":"<<dp[i][j][1]<<'\n';
}
}
ll res=dp[18][k][0];cout<<res;while(c0--)cout<<'0';cout<<'\n';return;
}
};
int main()
{
//freopen("3.in","r",stdin);
//cout<<fixed<<setprecision(12);
ios::sync_with_stdio(0);cin.tie(0);
int t=1;cin>>t;o=(t>50);
//clock_t a=clock();
while(t--){S SS;SS.solve();}
//cout<<"Time:"<<double(clock()-a)<<'\n';
}
详细
Test #1:
score: 100
Accepted
time: 0ms
memory: 3564kb
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: 1ms
memory: 3624kb
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
Wrong Answer
time: 14ms
memory: 3544kb
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:
909901919090999191 17
result:
wrong answer 1st lines differ - expected: '88988908810000', found: '909901919090999191 17'