結果
問題 |
No.3290 Encrypt Failed, but Decrypt Succeeded
|
ユーザー |
|
提出日時 | 2025-10-03 23:25:58 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 29 ms / 2,000 ms |
コード長 | 1,617 bytes |
コンパイル時間 | 998 ms |
コンパイル使用メモリ | 95,456 KB |
実行使用メモリ | 30,052 KB |
最終ジャッジ日時 | 2025-10-03 23:26:01 |
合計ジャッジ時間 | 2,535 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 27 |
ソースコード
#include <iostream> #include <algorithm> #include <vector> #include <string> #include <set> #include <unordered_set> #include <cstring> #include <queue> #include <bitset> #include <map> #include <stack> using namespace std; long long int n,k; long long int dp[300005]; string s; long long int solve(int idx) { if(s[idx]=='0') { return 0; } if(dp[idx]!=-1) { return dp[idx]; } if(idx==n) { dp[idx] = 1; return dp[idx]; } dp[idx] = 0; int x = 0; if(idx+1 <= n) { x = 10*x + (s[idx] - '0'); dp[idx] += solve(idx+1); } if(idx+2 <= n) { x = 10*x + (s[idx+1] - '0'); if(x<=26) { dp[idx] += solve(idx+2); } } if(dp[idx] >= 1e18) dp[idx] = 1e18; return dp[idx]; } int main() { cin.tie(0); ios::sync_with_stdio(false); cin >> n >> k; cin >> s; memset(dp,-1,sizeof(dp)); solve(0); string res = ""; int idx = 0; while(idx < n) { //cout << idx << ' ' << s[idx] << '\n'; if(k==0) break; if(s[idx]=='0') { break; } int x = 0; x = 10*x + (s[idx] - '0'); int y = x; if(idx+2 <= n) { y = 10*y + (s[idx+1] - '0'); if(y<=26 && dp[idx+2]!=-1) { if(k <= dp[idx+1]) { res += (char)(x-1+'a'); idx+=1; } else { if(dp[idx+1]!=-1) k -= dp[idx+1]; res += (char)(y-1+'a'); idx+=2; } } else { res += (char)(x-1+'a'); idx+=1; } } else { res += (char)(x-1+'a'); idx+=1; } } cout << res << '\n'; // string t = "supercalifragilisticexpialidocious"; // for(auto c : t) // { // cout << c - 'a' + 1 << ' ' << c << '\n'; // } // cout << '\n'; return 0; }