結果
| 問題 |
No.1458 Segment Function
|
| コンテスト | |
| ユーザー |
tnakao0123
|
| 提出日時 | 2021-04-01 18:10:54 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 4 ms / 2,000 ms |
| コード長 | 1,293 bytes |
| コンパイル時間 | 839 ms |
| コンパイル使用メモリ | 92,984 KB |
| 実行使用メモリ | 6,820 KB |
| 最終ジャッジ日時 | 2024-10-12 13:37:58 |
| 合計ジャッジ時間 | 2,022 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 32 |
ソースコード
/* -*- 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;
}
tnakao0123