結果
| 問題 |
No.2934 Digit Sum
|
| コンテスト | |
| ユーザー |
👑 potato167
|
| 提出日時 | 2024-10-13 19:53:26 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 24 ms / 2,000 ms |
| コード長 | 1,140 bytes |
| コンパイル時間 | 2,231 ms |
| コンパイル使用メモリ | 200,796 KB |
| 最終ジャッジ日時 | 2025-02-24 19:21:50 |
|
ジャッジサーバーID (参考情報) |
judge3 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 2 |
| other | AC * 25 |
ソースコード
#include <bits/stdc++.h>
using namespace std;
#define rep(i,a,b) for (int i=(int)(a);i<(int)(b);i++)
#define all(p) p.begin(),p.end()
using ll = long long;
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
ll N, K;
cin >> N >> K;
if (N >= 162){
cout << K << "\n";
return 0;
}
auto add = [&](ll a, ll b) -> ll {
return min(a + b, 1ll << 60);
};
vector<vector<ll>> dp(1);
dp[0].resize(N + 1);
rep(i, 0, N + 1) dp[0][i] = 1;
while (dp.back().back() <= K){
vector<ll> n_dp(N + 1);
rep(i, 0, N + 1) rep(d, 0, 10) if (i + d <= N){
n_dp[i + d] = add(n_dp[i + d], dp.back()[i]);
}
dp.push_back(n_dp);
}
ll sum = N;
bool ok = false;
for (int j = dp.size() - 1; j > 0; j--){
int d = 0;
rep(i, 0, 10){
if (dp[j - 1][sum - i] <= K){
K -= dp[j - 1][sum - i];
}
else{
d = i;
sum -= i;
break;
}
}
if (d) ok = true;
if (ok) cout << d;
}
cout << "\n";
}
potato167