QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#660367 | #6300. Best Carry Player 2 | Fluoresce | WA | 0ms | 3804kb | C++20 | 2.1kb | 2024-10-20 10:44:53 | 2024-10-20 10:44:53 |
Judging History
answer
#include<bits/stdc++.h>
#include<unordered_map>
#include<unordered_set>
typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
#define debug(a) cout<<a<<'\n'
#define Pll pair<ll,ll>
#define PII pair<int,int>
#define ft first
#define sd second
#define vec vector
#define pushk push_back
#define ump unordered_map
#define pl p<<1
#define pr p<<1|1
using namespace std;
const int N = 15 + 10, M = 1e4 + 10, mod = 1e9 + 7;
const ll inf = 1e18;
const ld eps = 1e-13;
int mov[4][2] = { {0,1},{1,0},{-1,0},{0,-1} }, dx, dy, _ = 1, __ = 1;
void bout(bool f) {
if (f)cout << "Yes\n";
else cout << "No\n";
}
ll n, m, k;
ull p[25],dp[25][2],pre[25][2];
void ini() {
p[0]=1;
for(int i=1;i<=19;++i)p[i]=10*p[i-1];
}
void solve() {
string s;
cin>>s>>k;
if(__>5){
if(__-_==17){
cout<<s<<' '<<k;
}
return;
}
reverse(s.begin(),s.end());
memset(dp,0x3f,sizeof dp);
dp[0][0]=0;
ll x,y,z;
for(int i=0;i<s.length();++i){
memcpy(pre,dp,sizeof dp);
memset(dp,0x3f,sizeof dp);
x=s[i]-'0';
if(x==9){
for(int j=1;j<=i+1;++j){
dp[j][0]=pre[j][0];
dp[j][1]=min(pre[j-1][0]+p[i],pre[j-1][1]);
}
}else{
for(int j=1;j<=i+1;++j){
dp[j][0]=min(pre[j][0],pre[j][1]);
if(x)dp[j][1]=min(pre[j-1][0]+(10-x)*p[i],pre[j-1][1]+(9-x)*p[i]);
else dp[j][1]=pre[j-1][1]+(9-x)*p[i];
}
}
dp[0][0]=0;
}
if(!k){
for(int i=0;i<=18;++i){
if(i<s.length())x=s[i]-'0';
else x=0;
if(x<9){
cout<<p[i]<<'\n';
break;
}
}
}
else {
x=min(dp[k][0],dp[k][1]);
if(x<dp[0][1]){
cout<<x<<'\n';
}else{
for(int i=k;i>=0;--i){
if(dp[i][1]>=dp[0][1])cout<<'9';
else{
cout<<dp[i][1]<<'\n';
break;
}
}
}
}
}
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
#ifndef ONLINE_JUDGE
streambuf* cinbackup = cin.rdbuf(), * coutbackup = cout.rdbuf();
ifstream fin("in.txt");
ofstream fout("out.txt");
cin.rdbuf(fin.rdbuf());
cout.rdbuf(fout.rdbuf());
#endif
cin >> _;
__ = _;
ini();
while (_--) {
solve();
}
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 3516kb
input:
4 12345678 0 12345678 5 12345678 18 990099 5
output:
1 54322 999999999987654322 9910
result:
ok 4 lines
Test #2:
score: -100
Wrong Answer
time: 0ms
memory: 3804kb
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:
999990000099999 16
result:
wrong answer 1st lines differ - expected: '100000', found: '999990000099999 16'