結果

問題 No.3290 Encrypt Failed, but Decrypt Succeeded
ユーザー eQe
提出日時 2025-10-03 22:33:49
言語 C++23
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 13 ms / 2,000 ms
コード長 2,282 bytes
コンパイル時間 3,307 ms
コンパイル使用メモリ 281,352 KB
実行使用メモリ 9,640 KB
最終ジャッジ日時 2025-10-03 22:34:02
合計ジャッジ時間 4,821 ms
ジャッジサーバーID
(参考情報)
judge1 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 27
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
#if __has_include(<atcoder/all>)
#endif
using namespace std;
#define eb emplace_back
#define LL(...) ll __VA_ARGS__;lin(__VA_ARGS__)
#define of(i,...) for(auto[i,i##stop,i##step]=for_range<ll>(1,__VA_ARGS__);i>=i##stop;i+=i##step)
#define fe(a,e,...) for(auto&&__VA_OPT__([)e __VA_OPT__(,__VA_ARGS__]):a)
#define defpp template<ostream&o=cout>void pp(const auto&...a){[[maybe_unused]]const char*c="";((o<<c<<a,c=" "),...);o<<'\n';}void epp(const auto&...a){pp<cerr>(a...);}
#define entry defpp void main();void main2();}int main(){my::io();my::main();}namespace my{
namespace my{
void io(){cin.tie(nullptr)->sync_with_stdio(0);cout<<fixed<<setprecision(15);}
using ll=long long;
template<class T>constexpr auto for_range(T s,T b){T a=0;if(s)swap(a,b);return array{a-s,b,1-s*2};}
void lin(auto&...a){(cin>>...>>a);}
auto encode_integer(char c){return c-'0';}
bool amin(auto&a,const auto&b){return b<a?a=b,1:0;}
template<class...A>using pack_back_t=tuple_element_t<sizeof...(A)-1,tuple<A...>>;
}
namespace my{
template<class V>struct vec;
template<int D,class T>struct hvec_helper{using type=vec<typename hvec_helper<D-1,T>::type>;};
template<class T>struct hvec_helper<0,T>{using type=T;};
template<int D,class T>using hvec=hvec_helper<D,T>::type;
template<class V>struct vec:vector<V>{
  using vector<V>::vector;
  auto&emplace_back(auto&&...a){vector<V>::emplace_back(std::forward<decltype(a)>(a)...);return*this;}
};
template<class...A>requires(sizeof...(A)>=2)vec(const A&...a)->vec<hvec<sizeof...(A)-2,pack_back_t<A...>>>;
auto sin(){string s;lin(s);return s;}
template<class T=ll>auto sinen_integer(){vec<T>r;fe(sin(),e)r.eb(encode_integer(e));return r;}
}
namespace my{entry
void main(){
  LL(N,K);
  auto T=sinen_integer();

  vec dp(N+1,ll{}); // dp[i]:i文字目以降を使って出来る文章の個数.
  dp[N]=1;
  of(i,N){
    if(T[i]==0)continue; // 0は一つ前の数字と一緒に使わないとダメ.

    dp[i]+=dp[i+1];
    amin(dp[i],K+1);

    if(i+1<N){
      if(T[i]*10+T[i+1]<=26)dp[i]+=dp[i+2];
      amin(dp[i],K+1);
    }
  }

  string res{};
  ll i=0;
  while(i<N){
    if(dp[i+1]>=K){
      res+='a'+(T[i]-1);
      i++;
    }
    else{
      K-=dp[i+1];
      res+='a'+(T[i]*10+T[i+1]-1);
      i+=2;
    }
  }
  pp(res);
}}
0