結果

問題 No.1458 Segment Function
ユーザー tnakao0123tnakao0123
提出日時 2021-04-01 18:10:54
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 4 ms / 2,000 ms
コード長 1,293 bytes
コンパイル時間 808 ms
コンパイル使用メモリ 92,984 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-04-20 17:41:41
合計ジャッジ時間 1,993 ms
ジャッジサーバーID
(参考情報)
judge2 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

/* -*- coding: utf-8 -*-
 *
 * 1458.cc:  No.1458 Segment Function - yukicoder
 */

#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<set>
#include<stack>
#include<list>
#include<queue>
#include<deque>
#include<algorithm>
#include<numeric>
#include<utility>
#include<complex>
#include<functional>
 
using namespace std;

/* constant */

const int MAX_L = 200000;
const int INF = 1 << 30;

const int fs[] = { 6, 2, 5, 5, 4, 5, 6, 4, 7, 6 };
//                 0, 1, 2, 3, 4, 5, 6, 7, 8, 9

/* typedef */

/* global variables */

char p[MAX_L + 4], q[MAX_L + 4];

/* subroutines */

int f(char s[]) {
  int sum = 0;
  for (int i = 0; s[i]; i++) {
    if (s[i] == '-') sum++;
    else sum += fs[s[i] - '0'];
  }
  return sum;
}

int f(int x) { // x > 0
  int sum = 0;
  while (x > 0) {
    sum += fs[x % 10];
    x /= 10;
  }
  return sum;
}

/* main */

int main() {
  scanf("%s%s", p, q);
  int ql = strlen(q);

  if (ql == 1 && q[0] == '0') { puts(p); return 0; }

  int n = (ql >= 9) ? INF : atoi(q);
  //printf("n=%d\n", n);

  int x = f(p);
  n--;
  //printf("f(%s)=%d\n", p, x);

  for (; n > 0; n--) {
    int y = f(x);
    if (x == y) break;
    x = y;
  }

  printf("%d\n", x);
  return 0;
}
0