結果

問題 No.1458 Segment Function
ユーザー e869120e869120
提出日時 2021-03-31 21:23:57
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 73 ms / 2,000 ms
コード長 1,098 bytes
コンパイル時間 880 ms
コンパイル使用メモリ 86,912 KB
実行使用メモリ 52,308 KB
最終ジャッジ日時 2024-04-20 17:36:10
合計ジャッジ時間 4,253 ms
ジャッジサーバーID
(参考情報)
judge4 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 63 ms
52,096 KB
testcase_01 AC 64 ms
51,968 KB
testcase_02 AC 62 ms
52,096 KB
testcase_03 AC 62 ms
51,968 KB
testcase_04 AC 60 ms
51,968 KB
testcase_05 AC 61 ms
51,968 KB
testcase_06 AC 61 ms
51,968 KB
testcase_07 AC 61 ms
51,968 KB
testcase_08 AC 65 ms
52,308 KB
testcase_09 AC 66 ms
52,308 KB
testcase_10 AC 64 ms
52,308 KB
testcase_11 AC 69 ms
52,048 KB
testcase_12 AC 65 ms
52,184 KB
testcase_13 AC 69 ms
52,096 KB
testcase_14 AC 67 ms
52,096 KB
testcase_15 AC 67 ms
51,968 KB
testcase_16 AC 68 ms
52,096 KB
testcase_17 AC 68 ms
51,840 KB
testcase_18 AC 72 ms
52,304 KB
testcase_19 AC 72 ms
52,304 KB
testcase_20 AC 72 ms
52,180 KB
testcase_21 AC 72 ms
52,308 KB
testcase_22 AC 72 ms
52,224 KB
testcase_23 AC 62 ms
52,096 KB
testcase_24 AC 55 ms
19,548 KB
testcase_25 AC 60 ms
52,096 KB
testcase_26 AC 72 ms
52,056 KB
testcase_27 AC 73 ms
52,184 KB
testcase_28 AC 50 ms
19,200 KB
testcase_29 AC 54 ms
19,544 KB
testcase_30 AC 54 ms
19,544 KB
testcase_31 AC 68 ms
51,840 KB
testcase_32 AC 65 ms
52,176 KB
testcase_33 AC 66 ms
52,184 KB
testcase_34 AC 65 ms
52,056 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