QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#658176 | #6300. Best Carry Player 2 | Fluoresce# | WA | 0ms | 3620kb | C++20 | 1.7kb | 2024-10-19 16:18:30 | 2024-10-19 16:18:35 |
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;
reverse(s.begin(),s.end());
memset(dp,0x3f,sizeof dp);
dp[0][0]=0;
int x,y,z;
for(int i=0;i<=18;++i){
memcpy(pre,dp,sizeof dp);
memset(dp,0x3f,sizeof dp);
if(i<s.length())x=s[i]-'0';
else x=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]);
dp[j][1]=min(pre[j-1][0]+(10-x)*p[i],pre[j-1][1]+(9-x)*p[i]);
}
}
dp[0][0]=0;
}
if(!k)cout<<1<<'\n';
else cout<<min(dp[k][0],dp[k][1])<<'\n';
}
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: 3620kb
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: 3552kb
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:
1 10000 1000 100 10 1 900001 9900001 99900001 999900001 10000000000 9999910000 9999901000 9999900100 9999900010 9999900001 9000009999900001 99000009999900001 999000009999900001 900000000000000000 1
result:
wrong answer 1st lines differ - expected: '100000', found: '1'