結果
問題 |
No.3290 Encrypt Failed, but Decrypt Succeeded
|
ユーザー |
|
提出日時 | 2025-09-16 22:33:03 |
言語 | C++23 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 15 ms / 2,000 ms |
コード長 | 2,641 bytes |
コンパイル時間 | 1,508 ms |
コンパイル使用メモリ | 160,120 KB |
実行使用メモリ | 7,716 KB |
最終ジャッジ日時 | 2025-09-16 22:33:07 |
合計ジャッジ時間 | 3,749 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 27 |
ソースコード
#include <algorithm> #include <cassert> #include <cstdio> #include <cstdlib> #include <cstring> #include <cmath> #include <iostream> #include <numeric> #include <vector> #include <map> #include <set> #include <queue> #include <functional> #include <iomanip> #include <ranges> using namespace std; using ll = long long; template<typename T> auto range(T s, T e) { return views::iota(s, max(s, e)); } template<typename T> auto range(T n) { return range<T>(0, n); } template<typename T> void take(vector<T>& vec, int n) { vec.resize(n); for (int i = 0; i < n; ++i) cin >> vec[i]; } template<class... Args> void sout(const Args &...args) { ((cout << args << ' '), ...); } template<class... Args> void soutn(const Args &...args) { ((cout << args << ' '), ...); cout << '\n'; } template<typename T1, typename T2> struct In2 { T1 a; T2 b; friend std::istream& operator>>(std::istream& is, In2& obj) { T1 t1; T2 t2; is >> t1 >> t2; obj = {t1, t2}; return is; } }; template<typename T1, typename T2, typename T3> struct In3 { T1 a; T2 b; T3 c; friend std::istream& operator>>(std::istream& is, In3& obj) { T1 t1; T2 t2; T3 t3; is >> t1 >> t2 >> t3; obj = {t1, t2, t3}; return is; } }; template<typename T1, typename T2, typename T3, typename T4> struct In4 { T1 a; T2 b; T3 c; T4 d; friend std::istream& operator>>(std::istream& is, In4& obj) { T1 t1; T2 t2; T3 t3; T4 t4; is >> t1 >> t2 >> t3 >> t4; obj = {t1, t2, t3, t4}; return is; } }; #ifdef LOCAL #include <debug.h> #else #define dump(...) ; #endif namespace { ll n, k; string t; void read() { cin >> n >> k >> t; } int digit(char c1, char c2) { return (c1 - '0') * 10 + c2 - '0'; } string run() { vector<ll> dp(n + 1); dp[n] = 1; for (int i = n - 1; i >= 0; --i) { if (t[i] != '0') { dp[i] += dp[i + 1]; if (i < n - 1) { int d = digit(t[i], t[i + 1]); if (10 <= d && d <= 26) dp[i] += dp[i + 2]; } } if (dp[i] > k) dp[i] = k + 1; // inf } dump(dp); string res; for (int i = 0; i < n; ) { assert(t[i] != '0'); if (k <= dp[i + 1]) { res += 'a' + digit('0', t[i]) - 1; i++; } else { k -= dp[i + 1]; res += 'a' + digit(t[i], t[i + 1]) - 1; i += 2; } } dump(res, k); assert(k == 1); return res; } } // namespace template <typename F> void exec(F f) { if constexpr (std::is_same_v<decltype(f()), void>) f(); else cout << f() << endl; } int main(int argc, char** argv) { cerr << fixed << setprecision(12); cout << fixed << setprecision(12); int testcase = 1; if (argc > 1) testcase = atoi(argv[1]); while (testcase--) { read(); } exec(run); }