QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#658135#6300. Best Carry Player 2Fluoresce#WA 0ms3612kbC++201.7kb2024-10-19 16:13:502024-10-19 16:13:56

Judging History

你现在查看的是最新测评结果

  • [2024-10-19 16:13:56]
  • 评测
  • 测评结果:WA
  • 用时:0ms
  • 内存:3612kb
  • [2024-10-19 16:13:50]
  • 提交

answer

#include<bits/stdc++.h>
#include<unordered_map>
#include<unordered_set>
typedef long long ll;
typedef long double ld;
#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;
ll 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<k;++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: 0
Wrong Answer
time: 0ms
memory: 3612kb

input:

4
12345678 0
12345678 5
12345678 18
990099 5

output:

1
54322
999999999987654322
9901

result:

wrong answer 4th lines differ - expected: '9910', found: '9901'