結果

問題 No.3290 Encrypt Failed, but Decrypt Succeeded
ユーザー moon17
提出日時 2025-10-03 22:57:03
言語 C++23
(gcc 13.3.0 + boost 1.87.0)
結果
WA  
実行時間 -
コード長 1,291 bytes
コンパイル時間 3,358 ms
コンパイル使用メモリ 281,208 KB
実行使用メモリ 7,720 KB
最終ジャッジ日時 2025-10-03 22:57:09
合計ジャッジ時間 4,491 ms
ジャッジサーバーID
(参考情報)
judge1 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 8 WA * 19
権限があれば一括ダウンロードができます

ソースコード

diff #

// Original Python3 code:
/*
n,k=map(int,input().split())
t=[*map(int,input())]
d=[0]*(1+n)
d[n]=1
for i in range(n)[::-1]:
  if t[i]==0:
    continue
  if i+1>=n or t[i+1]:
    d[i]+=d[i+1]
  if i+1<n and 10<=t[i]*10+t[i+1]<=26:
    d[i]+=d[i+2]
i=0
ans=[]
a=ord('a')
while i<n:
  if k<=d[i+1]:
    ans+=chr(t[i]+a-1),
    i+=1
  else:
    ans+=chr(t[i]*10+t[i+1]+a-1),
    k-=d[i+1]
    i+=2
print(''.join(ans))
*/

#include <bits/stdc++.h>
using namespace std;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);

    int n;
    long long k; // k can be large
    cin >> n >> k;

    vector<int> t(n);
    for(int i = 0; i < n; ++i) {
        char c;
        cin >> c;
        t[i] = c - '0';
    }

    vector<long long> d(n+1, 0);
    d[n] = 1;

    for(int i = n-1; i >= 0; --i) {
        if(t[i] == 0) continue;
        if(i+1 >= n || t[i+1] != 0) d[i] += d[i+1];
        if(i+1 < n && 10 <= t[i]*10 + t[i+1] && t[i]*10 + t[i+1] <= 26)
            d[i] += d[i+2];
    }

    int i = 0;
    string ans;
    while(i < n) {
        if(k <= d[i+1]) {
            ans += char('a' + t[i] - 1);
            i += 1;
        } else {
            ans += char('a' + t[i]*10 + t[i+1] - 1);
            k -= d[i+1];
            i += 2;
        }
    }

    cout << ans << "\n";
}
0