結果

問題 No.1458 Segment Function
ユーザー boutarouboutarou
提出日時 2021-03-31 23:52:05
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 7 ms / 2,000 ms
コード長 1,950 bytes
コンパイル時間 2,412 ms
コンパイル使用メモリ 207,372 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-04-20 17:41:00
合計ジャッジ時間 3,126 ms
ジャッジサーバーID
(参考情報)
judge4 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,248 KB
testcase_01 AC 2 ms
5,376 KB
testcase_02 AC 1 ms
5,376 KB
testcase_03 AC 2 ms
5,376 KB
testcase_04 AC 2 ms
5,376 KB
testcase_05 AC 2 ms
5,376 KB
testcase_06 AC 2 ms
5,376 KB
testcase_07 AC 1 ms
5,376 KB
testcase_08 AC 3 ms
5,376 KB
testcase_09 AC 3 ms
5,376 KB
testcase_10 AC 2 ms
5,376 KB
testcase_11 AC 2 ms
5,376 KB
testcase_12 AC 3 ms
5,376 KB
testcase_13 AC 6 ms
5,376 KB
testcase_14 AC 6 ms
5,376 KB
testcase_15 AC 6 ms
5,376 KB
testcase_16 AC 6 ms
5,376 KB
testcase_17 AC 6 ms
5,376 KB
testcase_18 AC 7 ms
5,376 KB
testcase_19 AC 7 ms
5,376 KB
testcase_20 AC 7 ms
5,376 KB
testcase_21 AC 6 ms
5,376 KB
testcase_22 AC 7 ms
5,376 KB
testcase_23 AC 2 ms
5,376 KB
testcase_24 AC 2 ms
5,376 KB
testcase_25 AC 1 ms
5,376 KB
testcase_26 AC 7 ms
5,376 KB
testcase_27 AC 7 ms
5,376 KB
testcase_28 AC 2 ms
5,376 KB
testcase_29 AC 2 ms
5,376 KB
testcase_30 AC 2 ms
5,376 KB
testcase_31 AC 6 ms
5,376 KB
testcase_32 AC 2 ms
5,376 KB
testcase_33 AC 2 ms
5,376 KB
testcase_34 AC 2 ms
5,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#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;
}
0