結果

問題 No.1458 Segment Function
ユーザー SSRSSSRS
提出日時 2021-03-31 21:31:13
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 12 ms / 2,000 ms
コード長 1,003 bytes
コンパイル時間 2,434 ms
コンパイル使用メモリ 176,572 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-08-02 17:29:29
合計ジャッジ時間 3,592 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ(β)

テストケース

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

ソースコード

diff #

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