結果
問題 | No.2302 Carry X Times |
ユーザー | AngrySadEight |
提出日時 | 2023-04-11 01:58:23 |
言語 | C++17 (gcc 12.3.0 + boost 1.83.0) |
結果 |
AC
|
実行時間 | 81 ms / 2,000 ms |
コード長 | 1,553 bytes |
コンパイル時間 | 909 ms |
コンパイル使用メモリ | 83,628 KB |
実行使用メモリ | 5,376 KB |
最終ジャッジ日時 | 2024-04-16 03:08:05 |
合計ジャッジ時間 | 3,179 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge2 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 37 ms
5,248 KB |
testcase_01 | AC | 23 ms
5,376 KB |
testcase_02 | AC | 25 ms
5,376 KB |
testcase_03 | AC | 2 ms
5,376 KB |
testcase_04 | AC | 2 ms
5,376 KB |
testcase_05 | AC | 2 ms
5,376 KB |
testcase_06 | AC | 2 ms
5,376 KB |
testcase_07 | AC | 2 ms
5,376 KB |
testcase_08 | AC | 2 ms
5,376 KB |
testcase_09 | AC | 2 ms
5,376 KB |
testcase_10 | AC | 81 ms
5,376 KB |
testcase_11 | AC | 80 ms
5,376 KB |
testcase_12 | AC | 81 ms
5,376 KB |
testcase_13 | AC | 77 ms
5,376 KB |
testcase_14 | AC | 77 ms
5,376 KB |
testcase_15 | AC | 78 ms
5,376 KB |
testcase_16 | AC | 79 ms
5,376 KB |
testcase_17 | AC | 81 ms
5,376 KB |
testcase_18 | AC | 78 ms
5,376 KB |
testcase_19 | AC | 78 ms
5,376 KB |
testcase_20 | AC | 78 ms
5,376 KB |
testcase_21 | AC | 79 ms
5,376 KB |
testcase_22 | AC | 78 ms
5,376 KB |
testcase_23 | AC | 80 ms
5,376 KB |
testcase_24 | AC | 81 ms
5,376 KB |
ソースコード
#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; } }