結果
問題 | No.1458 Segment Function |
ユーザー |
|
提出日時 | 2021-03-31 21:41:25 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 5 ms / 2,000 ms |
コード長 | 1,315 bytes |
コンパイル時間 | 831 ms |
コンパイル使用メモリ | 80,824 KB |
最終ジャッジ日時 | 2025-01-20 03:03:34 |
ジャッジサーバーID (参考情報) |
judge2 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 32 |
ソースコード
#line 1 "main.cpp"#include <iostream>#include <algorithm>#include <numeric>#include <vector>#include <string>using namespace std;using lint = long long;const vector<int> fs{6, 2, 5, 5, 4, 5, 6, 4, 7, 6};int f(const string& s) {int ret = 0;for (auto c : s) {if (c == '-') {++ret;} else {ret += fs[c - '0'];}}return ret;}void solve() {string p, n;cin >> p >> n;if (n.length() <= 2) {// n <= 99なので全探索int m = stoi(n);while (m--) p = to_string(f(p));cout << p << "\n";} else {// n >= 100// とりあえず100回遷移for (int i = 0; i < 100; ++i) p = to_string(f(p));int x = p.front() - '0';// ループするまで遷移vector<int> xs{x};x = fs[x];while (x != xs.front()) {xs.push_back(x);x = fs[x];}int len = xs.size();// (n - 100) mod lenを求めるint s = 0;for (auto c : n) {s = (s * 10 + c - '0') % len;}s = ((s - 100) % len + len) % len;cout << xs[s] << "\n";}}int main() {cin.tie(nullptr);ios::sync_with_stdio(false);solve();return 0;}