結果
問題 | No.1458 Segment Function |
ユーザー |
![]() |
提出日時 | 2021-03-31 21:31:13 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 14 ms / 2,000 ms |
コード長 | 1,003 bytes |
コンパイル時間 | 1,882 ms |
コンパイル使用メモリ | 178,704 KB |
実行使用メモリ | 5,248 KB |
最終ジャッジ日時 | 2024-10-12 13:33:45 |
合計ジャッジ時間 | 3,030 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 32 |
ソースコード
#include <bits/stdc++.h> using namespace std; vector<int> c = {6, 2, 5, 5, 4, 5, 6, 4, 7, 6}; string f(string S){ if (S[0] == '-'){ return to_string(1 + stoi(f(S.substr(1)))); } int N = S.size(); int ans = 0; for (int i = 0; i < N; i++){ ans += c[S[i] - '0']; } return to_string(ans); } int main(){ string P; cin >> P; string N; cin >> N; if (N.size() < 2){ int N2 = stoi(N); for (int i = 0; i < N2; i++){ P = f(P); } cout << P << endl; } else { map<string, int> mp; mp[P] = 0; int t = 0; int c; while (true){ t++; P = f(P); if (mp.count(P)){ c = t - mp[P]; break; } else { mp[P] = t; } } int L = N.size(); int r = 0; for (int i = 0; i < L; i++){ r = (r * 10 + (N[i] - '0')) % c; } int t2 = t - 1; while (t2 % c != r){ t2--; } for (auto p : mp){ if (p.second == t2){ cout << p.first << endl; } } } }