結果
問題 | No.2302 Carry X Times |
ユーザー |
👑 ![]() |
提出日時 | 2023-04-11 01:58:23 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 76 ms / 2,000 ms |
コード長 | 1,553 bytes |
コンパイル時間 | 714 ms |
コンパイル使用メモリ | 80,628 KB |
最終ジャッジ日時 | 2025-02-12 04:56:33 |
ジャッジサーバーID (参考情報) |
judge2 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 1 |
other | AC * 24 |
ソースコード
#include <iostream>#include <map>using namespace std;typedef long long ll;ll mod = 998244353;ll calc(ll a_max, ll b_max, ll x, ll hascarry, map<pair<pair<ll,ll>, pair<ll,ll>>, ll> &mp){//cout << a_max << " " << b_max << " " << x << " " << hascarry << endl;ll ans = 0;if (a_max == 0 && b_max == 0){if (x == 0){return 1LL;}else{return 0LL;}}for (ll i = 0; i < 10; i++){for (ll j = 0; j < 10; j++){if (a_max - i < 0) continue;if (b_max - j < 0) continue;pair<ll,ll> p1 = pair<ll,ll>((a_max - i) / 10, (b_max - j) / 10);ll next_carry = (i + j + hascarry) / 10;pair<ll,ll> p2 = pair<ll,ll>(x - next_carry, next_carry);//cout << (a_max - i) / 10 << " " << (b_max - j) / 10 << " " << x - next_carry << " " << next_carry << endl;if (mp.find(pair<pair<ll,ll>,pair<ll,ll>>(p1, p2)) != mp.end()){ans = (ans + mp[pair<pair<ll,ll>, pair<ll,ll>>(p1, p2)]) % mod;}else{mp[pair<pair<ll,ll>, pair<ll,ll>>(p1, p2)] += calc((a_max - i) / 10, (b_max - j) / 10, x - next_carry, next_carry, mp);ans = (ans + mp[pair<pair<ll,ll>, pair<ll,ll>>(p1, p2)]) % mod;}}}return ans;}int main(){ll T;cin >> T;while(T--){ll N, X;cin >> N >> X;map<pair<pair<ll,ll>, pair<ll,ll>>, ll> mp;cout << calc(N, N, X, 0, mp) << endl;}}