結果
| 問題 |
No.1458 Segment Function
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2021-03-31 23:52:05 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 10 ms / 2,000 ms |
| コード長 | 1,950 bytes |
| コンパイル時間 | 3,716 ms |
| コンパイル使用メモリ | 203,616 KB |
| 最終ジャッジ日時 | 2025-01-20 04:36:57 |
|
ジャッジサーバーID (参考情報) |
judge1 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 32 |
ソースコード
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < int(n); i++)
using ll = long long;
using P = pair<int, int>;
int fx[] = {6, 2, 5, 5, 4, 5, 6, 4, 7, 6};
string f(string s) {
int res = 0;
rep(i, s.size()) {
if(s[i] == '-')
res++;
else {
int now = s[i] - '0';
res += fx[now];
}
}
return to_string(res);
}
int my_stoi(string s) {
int res = 0;
rep(i, s.size()) {
res *= 10;
res += s[i] - '0';
}
return res;
}
int main() {
cin.tie(0);
ios_base::sync_with_stdio(false);
string p, n;
cin >> p >> n;
if (n == "0") {
cout << p << endl;
return 0;
}
map<int, int> mp;
int start, syuuki;
for(int i = 1; 1; i++) {
p = f(p);
int now = my_stoi(p);
// cout << "now" << " " << now << endl;
if(mp[now] != 0) {
// mp[now]回進んでからの後は(i - mp[now])回周期で回るのだ
start = mp[now], syuuki = i - mp[now];
break;
}
mp[my_stoi(p)] = i;
}
// cout << start << " " << syuuki << endl;
// 周期が始まる前に終わるやつ
if (n.size() < 8 && my_stoi(n) < start) {
for (auto elem : mp) {
if (elem.second == my_stoi(n)) {
cout << elem.first << endl;
return 0;
}
}
}
int cnt = 0;
rep(i, n.size()) {
cnt *= 10;
cnt %= syuuki;
cnt += (int)n[i] - '0';
cnt %= syuuki;
}
cnt -= start;
cnt %= syuuki;
if(cnt < 0) cnt += syuuki;
// cout << start << " " << cnt << " " << syuuki << endl;
for(auto elem : mp) {
// cout << "{ " << elem.first << " " << elem.second << " }" << endl;
if(elem.second == start + cnt) {
cout << elem.first << endl;
return 0;
}
}
return 0;
}