結果
| 問題 |
No.1458 Segment Function
|
| コンテスト | |
| ユーザー |
QCFium
|
| 提出日時 | 2021-03-31 21:35:10 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 12 ms / 2,000 ms |
| コード長 | 851 bytes |
| コンパイル時間 | 1,627 ms |
| コンパイル使用メモリ | 174,972 KB |
| 実行使用メモリ | 5,248 KB |
| 最終ジャッジ日時 | 2024-10-12 13:34:24 |
| 合計ジャッジ時間 | 2,899 ms |
|
ジャッジサーバーID (参考情報) |
judge3 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 32 |
ソースコード
#include <bits/stdc++.h>
int ri() {
int n;
scanf("%d", &n);
return n;
}
int main() {
constexpr int data[] = {6, 2, 5, 5, 4, 5, 6, 4, 7, 6};
std::string s;
std::cin >> s;
int64_t n;
std::cin >> n;
if (n == 0) {
std::cout << s << std::endl;
return 0;
}
int cur = 0;
if (s[0] == '-') cur++, s.erase(s.begin());
for (auto i : s) cur += data[i - '0'];
auto apply = [&] (int x) {
int res = 0;
for (int t = x; t; t /= 10) res += data[t % 10];
return res;
};
std::map<int, int> res;
res[cur] = 1;
for (int i = 1; i < n; i++) {
int next = apply(cur);
if (res.count(next)) {
int period = (i + 1 - res[next]);
int left = (n - (i + 1)) % period;
for (int j = 0; j < left; j++) cur = apply(cur);
printf("%d\n", cur);
return 0;
}
res[next] = i + 1;
cur = next;
}
printf("%d\n", cur);
return 0;
}
QCFium