結果

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

ソースコード

diff #

#include<bits/stdc++.h>
using namespace std;
int main(){
  int n;
  long long k;
  cin>>n>>k;
  string t;
  cin>>t;
  string emp="";
  auto check=[&](int i,int j)->string{
    if(0>i||i>=n) return emp;
    if(i+j>n) return emp;
    if(j==1){
      if(t[i]=='0') return emp;
      else return string(1,char('a'+t[i]-'1'));
    }
    else{
      if(t[i]=='1') return string(1,char('a'+9+t[i+1]-'0'));
      else if(t[i]=='2'){
        if(t[i+1]<='6') return string(1,char('a'+19+t[i+1]-'0'));
        else return emp;
      }
      else return emp;
    }
  };
  vector<long long> dp(n+1);
  dp[n]=1;
  dp[n-1]=check(n-1,1)!=emp;
  for(int i=n-2;i>=0;i--){
    dp[i]=(check(i,1)!=emp)*dp[i+1]+(check(i,2)!=emp)*dp[i+2];
    if(dp[i]>=k) dp[i]=k;
  }
  string ans="";
  int idx=0;
  while(idx<n){
    if(check(idx,1)!=emp&&k<=dp[idx+1]){
      ans+=check(idx,1);
      idx++;
    }
    else{
      ans+=check(idx,2);
      k-=dp[idx+1];
      idx+=2;
    }
  }
  cout<<ans<<endl;
}
0