結果

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

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
// #include<atcoder/all>
// using mint = atcoder::modint998244353;
using ld = long double;
#define fi first
#define se second
#define all(x) x.begin(),x.end()
#define rep(i,n) for(int i=0;i<(int)(n);++i)
template<typename T>bool chmin(T&a,T b){return b<a?(a=b,1):0;}
template<typename T>bool chmax(T&a,T b){return b>a?(a=b,1):0;}

int main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    
    long N,K;
    cin>>N>>K;
    string T;
    cin>>T;
    auto f=[&](int i)->bool {
        if(i>=N-1) return 0;
        char a=T[i];
        char b=T[i+1];
        return (a!='0'&&(a-'0')*10+(b-'0')<=26);
    };
    vector<long> dp(N+1,0);
    dp[N]=1;
    dp[N-1]=(T[N-1]!='0');
    for(int i=N-1;i--;){
        if(T[i]!='0') dp[i]+=dp[i+1];
        if(f(i)) dp[i]+=dp[i+2];
        chmin(dp[i], (long)2e18);
    }

    int now=0;
    while(now!=N){
        while(T[now]=='0');
        if(K<=dp[now+1]){
            cout<<(char)('a'+T[now]-'1');
            now++;
        }
        else{
            cout<<(char)('a'+((T[now]-'0')*10+T[now+1]-'1'));
            K-=dp[now+1];
            now+=2;
        }
    }
    cout<<"\n";
}
0