結果
問題 |
No.3290 Encrypt Failed, but Decrypt Succeeded
|
ユーザー |
|
提出日時 | 2025-10-03 22:06:22 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 1,423 bytes |
コンパイル時間 | 880 ms |
コンパイル使用メモリ | 95,456 KB |
実行使用メモリ | 20,708 KB |
最終ジャッジ日時 | 2025-10-03 22:06:27 |
合計ジャッジ時間 | 2,363 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 2 WA * 1 |
other | AC * 4 WA * 23 |
ソースコード
#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(dp[idx]!=-1) { return dp[idx]; } if(idx==n) { dp[idx] = 1; return dp[idx]; } int idx2 = idx; dp[idx2] = 0; int x = 0; while(idx < n) { if(s[idx]!='0') break; idx+=1; } if(idx+1 <= n) { x = 10*x + (s[idx] - '0'); dp[idx2] += solve(idx+1); } if(idx+2 <= n) { x = 10*x + (s[idx+1] - '0'); if(x<=26) { dp[idx2] += solve(idx+2); } } return dp[idx2]; } 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) { while(idx < n) { if(s[idx]!='0') break; idx+=1; } if(idx==n) 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) { if(k <= dp[idx+1]) { res += (char)(x-1+'a'); idx+=1; } else { 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'; return 0; }