QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#111307#6300. Best Carry Player 2xaphoenix#WA 2ms3476kbC++172.2kb2023-06-06 17:36:122023-06-06 17:36:16

Judging History

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

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

answer

#include<bits/stdc++.h>
using namespace std;

#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define LC ch[k][0] 
#define RC ch[k][1]
#define IO cin.sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define all(x) (x).begin(), (x).end()
#define SZ(x) ((int)(x).size())
#define rep(i,a,n) for (int i = a; i < n; i++)
#define repn(i,a,n) for (int i = a; i <= n; i++)
#define per(i,a,n) for (int i = n - 1; i >= a; i--)
#define pern(i,a,n) for (int i = n; i >= a; i--)

typedef long long LL;
typedef unsigned long long ull;
typedef pair<int, int> PII;
typedef pair<double, double> PDD;

const int N = 100010;
const int M = 610000;
const int mod = 1e9+7;
const int inf = (int)1e9;
const LL INF = (LL)1e18;
const double eps = 1e-9;

__int128 x;
int k;
__int128 dp[40][40][2], tp[40];
int xt[40];
void write(__int128 a)
{
    if(a<0)
    {
        cout<<'-';
        a=-a;
    }
    if(a>9)
        write(a/10);
    cout<<(int)(a%10);
}

__int128 read()
{
    __int128 temp=0;
    string a;
    getline(cin,a);
    for(int i=0;i<a.size();i++)
    {
        temp*=10;
        temp+=a[i]-'0';
    }
    return temp;
}

void solve() {
	int tmp;
	cin >> tmp;
	x = tmp;
	cin >> k;
	string ans = "";
	if (k == 0) {
		while (tmp % 10 == 9) {
			tmp /= 10; ans += "0";
		}
		ans += "1"; 
		reverse(ans.begin(), ans.end());
		cout << ans << "\n";
		return;
	}
	__int128 num = x; int pos = 0;
	while (num) {
		xt[pos] = num % 10; num /= 10;
		pos ++;
	}
	repn(i, 0, 37) {
		repn(j, 0, 37) repn(k, 0, 1) dp[i][j][k] = tp[37];
	}
	dp[37][1][1] = 0; dp[37][0][0] = 0;
	pern(i, 0, 36) {
		repn(k1, 0, 1){
			repn(k2, 0, 1) {
				if (k1 && k2 + xt[i] == 0) continue;
				if (!k1 && k2 + xt[i] > 9) continue;
				__int128 ky = 0;
				if (k1) ky = 10 - (k2 + xt[i]);
				ky *= tp[i];
				repn(j, k2, 38 - i) {
					dp[i][j][k2] = min(dp[i][j][k2], dp[i + 1][j - k2][k1] + ky);
				}
			}
		}
	}
	write(dp[0][k][0]); cout << "\n";
}

int main()
{
	IO;
	tp[0] = 1;
	repn(i, 1, 37) tp[i] = tp[i - 1] * 10;
	int T;
	cin >> T;
	repn(i, 1, T) solve();
	return 0;
}
/*
4
12345678 0
12345678 5
12345678 18
990099 5
*/

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 2ms
memory: 3476kb

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: 3400kb

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
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1

result:

wrong answer 1st lines differ - expected: '100000', found: '1'