結果

問題 No.3290 Encrypt Failed, but Decrypt Succeeded
ユーザー 00 Sakuda
提出日時 2025-10-03 21:45:21
言語 C++23
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 14 ms / 2,000 ms
コード長 922 bytes
コンパイル時間 1,078 ms
コンパイル使用メモリ 113,880 KB
実行使用メモリ 7,716 KB
最終ジャッジ日時 2025-10-03 21:45:25
合計ジャッジ時間 2,672 ms
ジャッジサーバーID
(参考情報)
judge2 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 27
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <vector>
#include <set>
#include <map>
#include <algorithm>
#include <iomanip>
#include <numeric>
using namespace std;
using ll = long long;
char toc(int a) {
	char now = 'a';
	a--;
	now += a;
	return now;
}
int main() {
	int N;ll K;cin >> N >> K;
	string T;cin >> T;
	vector<ll> dp(N+3, 0);
	dp[N] = 1;
	dp[N+1] = 1;
	for (int i = N-1;i >= 0;i--) {
		//split by one pattern
		int a = T[i] - '0';
		if (a != 0) dp[i] = min(K+2, dp[i+1]);
		//split by two pattern
		if (i+1 < N) {
			int b = T[i+1] - '0';
			if (a != 0 and ((10*a)+b) <= 26) {
				dp[i] = min(K+2, dp[i] + dp[i+2]);
			}
		}
	}
	string ret = "";
	int it = 0;
	while (it < N) {
		int a = T[it] - '0';
		if (a != 0) {
			ll dp1 = dp[it+1];
			if (dp1 >= K) {
				ret += toc(a);
				it++;
				continue;
			}
			K -= dp1;
		}
		int b = T[it+1] - '0';
		int c = (10 * a) + b;
		ret += toc(c);
		it += 2;
	}
	cout << ret << endl;
}

0