QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#568210#8347. 毒假强bear013160 33ms4232kbC++142.2kb2024-09-16 15:34:282024-09-16 15:34:29

Judging History

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

  • [2024-09-16 15:34:29]
  • 评测
  • 测评结果:60
  • 用时:33ms
  • 内存:4232kb
  • [2024-09-16 15:34:28]
  • 提交

answer

#include<bits/stdc++.h>
#define rep(i, n) for(int i = 0; i < n; ++i)
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef pair<int, int> pii;
const int inf = 0x3f3f3f3f;
const ll INF = 0x3f3f3f3f3f3f3f3fll;
template<typename T> inline void chmax(T &_a, const T &_b){ (_b>_a) ? (_a=_b) : (_a); }
template<typename T> inline void chmin(T &_a, const T &_b){ (_b<_a) ? (_a=_b) : (_a); }

int k; ll n;

inline void uadd(ll &a, const ll &b){ a += b; if(a >= INF) a = INF; }
inline ll add(const ll &a, const ll &b){ return (a + b >= INF) ? INF : (a + b); }
inline ll mul(const ll &a, const ll &b){ if(a > INF / b) return INF; else return a * b; }
ll dp[20][500];
int ans[100];
ll f[100][1010];

ll calc(int lvl){
	int lmt = (50 / k);
	ll ret = 0;
	for(int cc = 1; cc <= lmt; ++cc){
		int x[100];
		{
			__int128 tmp = 1;
			rep(i, k) tmp *= 10;
			--tmp;
			tmp *= cc;
			rep(i, k) x[i] = (int)(tmp % 10), tmp /= 10;
			x[k] = (int)(tmp);
		}
		memset(dp, 0, sizeof(dp));
		dp[0][0] = 1;
		rep(i, k){
			int sum = 0, cnt = 0;
			for(int j = i; j <= 50; j += k){
				if(j >= lvl) sum += ans[j];
				else ++cnt;
			}
			for(int pre = 0; pre <= lmt; ++pre) for(int nxt = 0; nxt <= lmt; ++nxt){
				int targ = nxt * 10 + x[i] - pre - sum;
				if(targ < 0 || targ > cnt * 8) continue;
				uadd(dp[i + 1][nxt], mul(dp[i][pre], f[cnt][targ]));
			}
		}
		//cout << "  " << cc << ": " << x[k] << ": " << dp[k][x[k]] << "\n";
		uadd(ret, dp[k][x[k]]);
	}
	return ret;
}

int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);

	f[0][0] = 1;
	for(int i = 0; i <= 50; ++i) for(int j = 0; j <= 8 * i; ++j) rep(x, 9)
		uadd(f[i + 1][j + x], f[i][j]);

	cin >> k >> n;

	memset(ans, -1, sizeof(ans));
	for(int i = 50; i >= 0; --i){
		for(int x = 0; x <= 8; ++x){
			ans[i] = x;
			ll ret = calc(i);
			if(ret >= n) break;
			else n -= ret;
		}
		//cout << i << ": " << ans[i] << endl;
	}

	ll div = 1; rep(i, k) div *= 10; --div;
	ll res = 0; __int128 rem = 0;
	for(int i = 50; i >= 0; --i){
		rem = rem * 10 + ans[i];
		res = (ll)(res * 10 + rem / div); rem %= div;
	}
	assert(rem == 0);
	cout << res << "\n";

	return 0;
}

詳細信息

Subtask #1:

score: 25
Accepted

Test #1:

score: 25
Accepted
time: 6ms
memory: 3996kb

input:

2 653

output:

1069

result:

ok single line: '1069'

Test #2:

score: 25
Accepted
time: 3ms
memory: 3936kb

input:

2 729

output:

1168

result:

ok single line: '1168'

Test #3:

score: 25
Accepted
time: 3ms
memory: 3996kb

input:

2 378

output:

569

result:

ok single line: '569'

Test #4:

score: 25
Accepted
time: 3ms
memory: 4000kb

input:

3 673

output:

1329

result:

ok single line: '1329'

Test #5:

score: 25
Accepted
time: 4ms
memory: 3940kb

input:

3 803

output:

1514

result:

ok single line: '1514'

Test #6:

score: 25
Accepted
time: 0ms
memory: 4232kb

input:

3 999

output:

1772

result:

ok single line: '1772'

Test #7:

score: 25
Accepted
time: 16ms
memory: 3932kb

input:

1 754

output:

1142

result:

ok single line: '1142'

Test #8:

score: 25
Accepted
time: 4ms
memory: 4160kb

input:

3 673

output:

1329

result:

ok single line: '1329'

Test #9:

score: 25
Accepted
time: 3ms
memory: 3932kb

input:

3 728

output:

1390

result:

ok single line: '1390'

Test #10:

score: 25
Accepted
time: 3ms
memory: 4228kb

input:

3 644

output:

1277

result:

ok single line: '1277'

Test #11:

score: 25
Accepted
time: 3ms
memory: 3880kb

input:

3 403

output:

734

result:

ok single line: '734'

Test #12:

score: 25
Accepted
time: 6ms
memory: 3992kb

input:

2 196

output:

286

result:

ok single line: '286'

Test #13:

score: 25
Accepted
time: 15ms
memory: 4200kb

input:

1 73

output:

90

result:

ok single line: '90'

Test #14:

score: 25
Accepted
time: 6ms
memory: 3964kb

input:

2 661

output:

1079

result:

ok single line: '1079'

Test #15:

score: 25
Accepted
time: 15ms
memory: 3936kb

input:

1 648

output:

889

result:

ok single line: '889'

Subtask #2:

score: 35
Accepted

Test #16:

score: 35
Accepted
time: 27ms
memory: 4032kb

input:

1 345034715579071096

output:

2513029422339367072

result:

ok single line: '2513029422339367072'

Test #17:

score: 35
Accepted
time: 30ms
memory: 4196kb

input:

1 928064447724082316

output:

6841649390539291284

result:

ok single line: '6841649390539291284'

Test #18:

score: 35
Accepted
time: 28ms
memory: 3964kb

input:

1 541392330132197148

output:

3934945708734153715

result:

ok single line: '3934945708734153715'

Test #19:

score: 35
Accepted
time: 26ms
memory: 3988kb

input:

1 932096632324717020

output:

6866796948572468426

result:

ok single line: '6866796948572468426'

Test #20:

score: 35
Accepted
time: 33ms
memory: 3936kb

input:

1 114451898294099023

output:

751984975176342275

result:

ok single line: '751984975176342275'

Test #21:

score: 35
Accepted
time: 26ms
memory: 3936kb

input:

1 235498410350575794

output:

1678575115834518445

result:

ok single line: '1678575115834518445'

Test #22:

score: 35
Accepted
time: 30ms
memory: 4160kb

input:

1 263087596959546780

output:

1854129753611416834

result:

ok single line: '1854129753611416834'

Test #23:

score: 35
Accepted
time: 30ms
memory: 4232kb

input:

1 576677905677423798

output:

4168653345619750896

result:

ok single line: '4168653345619750896'

Test #24:

score: 35
Accepted
time: 27ms
memory: 4200kb

input:

1 715338160945566811

output:

5200349120580131175

result:

ok single line: '5200349120580131175'

Test #25:

score: 35
Accepted
time: 28ms
memory: 4156kb

input:

1 732471942288061103

output:

5313900915618634928

result:

ok single line: '5313900915618634928'

Test #26:

score: 35
Accepted
time: 22ms
memory: 3884kb

input:

1 81591921669173834

output:

533613350411224447

result:

ok single line: '533613350411224447'

Test #27:

score: 35
Accepted
time: 28ms
memory: 4232kb

input:

1 444041620832982561

output:

3172902012381803952

result:

ok single line: '3172902012381803952'

Test #28:

score: 35
Accepted
time: 30ms
memory: 4232kb

input:

1 6697181292380282

output:

39407408296042592

result:

ok single line: '39407408296042592'

Test #29:

score: 35
Accepted
time: 27ms
memory: 3928kb

input:

1 952035664236484391

output:

7007633864782456009

result:

ok single line: '7007633864782456009'

Test #30:

score: 35
Accepted
time: 28ms
memory: 4036kb

input:

1 119337166106580019

output:

792828609748126894

result:

ok single line: '792828609748126894'

Subtask #3:

score: 0
Wrong Answer

Test #31:

score: 0
Wrong Answer
time: 2ms
memory: 4192kb

input:

12 874620678069272691

output:

4017081068476267754

result:

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