結果

問題 No.1458 Segment Function
ユーザー e869120e869120
提出日時 2021-03-31 21:23:57
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 60 ms / 2,000 ms
コード長 1,098 bytes
コンパイル時間 767 ms
コンパイル使用メモリ 84,736 KB
実行使用メモリ 52,880 KB
最終ジャッジ日時 2023-08-02 17:29:12
合計ジャッジ時間 4,118 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 50 ms
52,488 KB
testcase_01 AC 51 ms
52,488 KB
testcase_02 AC 51 ms
52,512 KB
testcase_03 AC 51 ms
52,564 KB
testcase_04 AC 50 ms
52,692 KB
testcase_05 AC 49 ms
52,564 KB
testcase_06 AC 50 ms
52,812 KB
testcase_07 AC 51 ms
52,652 KB
testcase_08 AC 55 ms
52,700 KB
testcase_09 AC 53 ms
52,716 KB
testcase_10 AC 54 ms
52,748 KB
testcase_11 AC 54 ms
52,632 KB
testcase_12 AC 54 ms
52,776 KB
testcase_13 AC 54 ms
52,532 KB
testcase_14 AC 54 ms
52,492 KB
testcase_15 AC 56 ms
52,568 KB
testcase_16 AC 55 ms
52,692 KB
testcase_17 AC 56 ms
52,516 KB
testcase_18 AC 60 ms
52,880 KB
testcase_19 AC 60 ms
52,696 KB
testcase_20 AC 59 ms
52,676 KB
testcase_21 AC 60 ms
52,700 KB
testcase_22 AC 60 ms
52,700 KB
testcase_23 AC 50 ms
52,536 KB
testcase_24 AC 45 ms
20,188 KB
testcase_25 AC 50 ms
52,724 KB
testcase_26 AC 58 ms
52,692 KB
testcase_27 AC 59 ms
52,672 KB
testcase_28 AC 41 ms
19,748 KB
testcase_29 AC 45 ms
20,064 KB
testcase_30 AC 45 ms
19,856 KB
testcase_31 AC 54 ms
52,568 KB
testcase_32 AC 54 ms
52,644 KB
testcase_33 AC 53 ms
52,692 KB
testcase_34 AC 53 ms
52,672 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <map>
#include <cmath>
#include <queue>
#include <vector>
#include <string>
#include <algorithm>
#include <functional>
using namespace std;
#pragma warning (disable: 4996)

string S;
long long N;
long long A[10] = { 6, 2, 5, 5, 4, 5, 6, 4, 7, 6 };
long long nex[1 << 22];
long long vis[1 << 22];

void init() {
	for (int i = 0; i <= 2000000; i++) {
		string I = to_string(i);
		int cnt = 0;
		for (int j = 0; j < I.size(); j++) cnt += A[I[j] - '0'];
		nex[i] = cnt;
	}
}

int main() {
	cin >> S >> N;
	init();

	if (N == 0) {
		cout << S << endl;
	}
	else {
		long long wa = 0;
		for (int i = 0; i < S.size(); i++) {
			if (S[i] == '-') wa += 1;
			else wa += A[S[i] - '0'];
		}
		N -= 1;
		for (int i = 0; i < (1 << 22); i++) vis[i] = -1;

		int cx = wa, cnt = 0;
		vector<int> vec;
		for (int t = 0; t < N; t++) {
			vec.push_back(cx);
			if (vis[cx] != -1) {
				long long loops = t - vis[cx];
				long long r = vis[cx] + (N - vis[cx]) % loops;
				cout << vec[r] << endl;
				return 0;
			}
			vis[cx] = t;
			cx = nex[cx];
		}
		cout << cx << endl;
	}
	return 0;
}
0