結果
問題 | No.8101 砂嵐 |
ユーザー |
![]() |
提出日時 | 2023-03-31 22:58:26 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 2 ms / 1,000 ms |
コード長 | 736 bytes |
コンパイル時間 | 1,671 ms |
コンパイル使用メモリ | 174,732 KB |
実行使用メモリ | 5,376 KB |
最終ジャッジ日時 | 2024-09-23 02:00:01 |
合計ジャッジ時間 | 3,297 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 62 |
ソースコード
#include <bits/stdc++.h> using namespace std; typedef long long ll; ll toInt(string s, ll b = 10) { assert(b > 1); ll res = 0; for (char c : s) { res *= b; res += c - '0'; } return res; } string toStr(ll x, ll b = 10) { assert(b > 1 && x >= 0); if (x == 0) return "0"; string res; while (x) { res += (x % b) + '0'; x /= b; } reverse(res.begin(), res.end()); return res; } int main() { ll n; cin >> n; map<ll, ll> memo; auto f = [&](auto self, ll x) -> ll { if (x < 10) return 0; if (memo.count(x)) return memo[x]; string s = toStr(x); ll next = 1; for (auto c : s) { next *= int(c - '0'); } ll res = 1 + self(self, next); memo[x] = res; return res; }; cout << f(f, n) << endl; return 0; }