結果
| 問題 |
No.3290 Encrypt Failed, but Decrypt Succeeded
|
| ユーザー |
Today03
|
| 提出日時 | 2025-10-03 22:04:56 |
| 言語 | C++23 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 8 ms / 2,000 ms |
| コード長 | 1,759 bytes |
| コンパイル時間 | 3,340 ms |
| コンパイル使用メモリ | 279,096 KB |
| 実行使用メモリ | 7,720 KB |
| 最終ジャッジ日時 | 2025-10-03 22:05:01 |
| 合計ジャッジ時間 | 3,940 ms |
|
ジャッジサーバーID (参考情報) |
judge1 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 27 |
ソースコード
#include <bits/stdc++.h>
using namespace std;
#define ALL(x) (x).begin(), (x).end()
#define REP(i, n) for(int i=0; i<n; i++)
bool chmax(auto& a, auto b) { return a<b ? a=b, true : false; }
bool chmin(auto& a, auto b) { return a>b ? a=b, true : false; }
using ll=long long; const int INF=1e9+10; const ll INFL=4e18;
#ifdef DEBUG
#include "./debug.hpp"
#else
#define debug(...)
#define print_line
#endif
//----------------------------------------------------------
/*
全部区切る場合が辞書順最小かな?
区切らない、とすると区切る場合よりも辞書順が大きくなる
後ろから見て、dp[i] := [i,N)における、作れる文字列の個数
*/
void solve() {
ll N,K; cin>>N>>K;
string S; cin>>S;
auto cut=[&](int i) {
if(i==N-1) return false;
if(S[i]=='1') return true;
if(S[i]=='2' && S[i+1]<='6') return true;
return false;
};
auto tochar=[&](int i) {
int x=S[i]-'0'; x*=10;
x+=S[i+1]-'0';
return char('a'+x-1);
};
vector<ll> dp(N+1);
dp[N]=1;
for(int i=N-1; i>=0; i--) {
if(S[i]=='0') {
dp[i-1]+=dp[i+1];
i--;
continue;
}
dp[i]+=dp[i+1];
if(cut(i)) dp[i]+=dp[i+2];
chmin(dp[i],INFL);
}
debug(dp);
string ans;
K--;
for(int i=0; i<N; i++) {
if(dp[i+1]<=K && cut(i) || i<N-1 && S[i+1]=='0') {
K-=dp[i+1];
ans+=tochar(i);
i++;
} else {
ans+=char('a'+(S[i]-'0')-1);
}
}
cout<<ans<<endl;
}
int main() {
ios::sync_with_stdio(false); cin.tie(nullptr);
//cout<<fixed<<setprecision(15);
int T=1; //cin>>T;
while(T--) solve();
}
Today03