QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#104967#6300. Best Carry Player 2jeffqiWA 2ms3640kbC++231.7kb2023-05-12 17:35:022023-05-12 17:35:06

Judging History

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

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2023-05-12 17:35:06]
  • 评测
  • 测评结果:WA
  • 用时:2ms
  • 内存:3640kb
  • [2023-05-12 17:35:02]
  • 提交

answer

#include<bits/stdc++.h>
#define rep(i,a,b) for (int i = (a); i <= (b); ++i)
#define drep(i,a,b) for (int i = (a); i >= (b); --i)
#define LL long long
#define pii pair<int,int>
#define pll pair<LL,LL>
#define fi first
#define se second
#define mp make_pair
#define vi vector<int>
#define eb emplace_back
#define all(v) v.begin(),v.end()
#define sz(v) ((int)v.size())
using namespace std;
LL read() {
	LL x = 0,y = 1; char ch = getchar(); while (!isdigit(ch)) {if (ch == '-') y = -y; ch = getchar();}
	while (isdigit(ch)) {x = x*10+ch-'0'; ch = getchar();} return x*y;
}
const int tst = 0,rd = 1; int getflg = 0;
namespace qiqi {
	const int N = 50; const __int128 INF = 0x3f3f3f3f3f3f3f3f3f3f3f3f3f3f3f3f; LL n,m; __int128 pw[N],dp[N][N][2];
	void init() {
		pw[0] = 1; rep(i,1,N-1) pw[i] = 10*pw[i-1];
	}
	void print(__int128 x) {
		vi p; while (x) {p.eb(x%10); x /= 10;}
		reverse(all(p)); for (auto k:p) printf("%d",k);
	}
	void main() {
		n = read(); m = read();
		vi a; while (n) {a.eb(n%10); n /= 10;} a.resize(N);
		rep(i,0,N-1) rep(j,0,m) rep(k,0,1) dp[i][j][k] = INF;
		dp[N-1][0][0] = dp[N-1][0][1] = 0;
		drep(i,N-1,1) rep(j,0,m) {
			if (dp[i][j][0] < INF) {
				dp[i-1][j][0] = min(dp[i-1][j][0],dp[i][j][0]);
				if (a[i-1] != 9) dp[i-1][j][1] = min(dp[i-1][j][1],dp[i][j][0]);
			}
			if (dp[i][j][1] < INF) {
				if (a[i-1]) dp[i-1][j+1][0] = min(dp[i-1][j+1][0],dp[i][j][1]+(10-a[i-1])*pw[i-1]);
				dp[i-1][j+1][1] = min(dp[i-1][j+1][1],dp[i][j][1]+(9-a[i-1])*pw[i-1]);
			}
		}
		__int128 ans = dp[0][m][0];
		if (!ans) {
			rep(i,0,N-1) {
				if (a[i] != 9) {ans += pw[i]; break;}
			}
		}
		print(ans); puts("");
	}
}
int main() {
	qiqi::init(); int T = read(); while (T--) qiqi::main(); return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 1ms
memory: 3640kb

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: 2ms
memory: 3620kb

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
4557430888798830399
1000000000000000000

result:

wrong answer 20th lines differ - expected: '99999999999999999900000000000000000', found: '4557430888798830399'