結果

問題 No.3290 Encrypt Failed, but Decrypt Succeeded
ユーザー titia
提出日時 2025-10-08 04:16:15
言語 C++23
(gcc 13.3.0 + boost 1.87.0)
結果
RE  
実行時間 -
コード長 2,900 bytes
コンパイル時間 3,594 ms
コンパイル使用メモリ 287,404 KB
実行使用メモリ 33,064 KB
最終ジャッジ日時 2025-10-08 04:16:25
合計ジャッジ時間 9,249 ms
ジャッジサーバーID
(参考情報)
judge3 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 8 WA * 3 RE * 16
権限があれば一括ダウンロードができます

ソースコード

diff #

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

string S;
vector<string> X;
vector<ll> DP, DP2;
int N;
ll K;

ll calc(int x);
ll calc2(int x);

ll calc(int x) {
    if (DP[x] != -1) return DP[x];

    if (x >= (int)X.size() - 1) {
        DP[x] = 1;
        return 1;
    }

    string a = X[x] + X[x + 1];

    if (a.find('j') != string::npos || a.find('t') != string::npos) {
        ll ANS = calc(x + 1);
        DP[x] = ANS;
        return ANS;
    }

    int ai = stoi(a);
    if ((11 <= ai && ai <= 19) || (21 <= ai && ai <= 26)) {
        ll ANS = calc(x + 2) * 2 + calc2(x + 1);
        DP[x] = ANS;
        return ANS;
    } else {
        ll ANS = calc(x + 1);
        DP[x] = ANS;
        return ANS;
    }
}

ll calc2(int x) {
    if (DP2[x] != -1) return DP2[x];

    if (x >= (int)X.size() - 1) {
        DP2[x] = 0;
        return 0;
    }

    string a = X[x] + X[x + 1];

    if (a.find('j') != string::npos || a.find('t') != string::npos) {
        DP2[x] = 0;
        return 0;
    }

    int ai = stoi(a);
    if ((11 <= ai && ai <= 19) || (21 <= ai && ai <= 26)) {
        ll ANS = calc(x + 2);
        DP2[x] = ANS;
        return ANS;
    } else {
        DP2[x] = 0;
        return 0;
    }
}

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

    cin >> N >> K;
    cin >> S;

    if (K == 1) {
        string ANS;
        for (int i = 0; i < N; i++) {
            ANS.push_back((char)(S[i] - '0' + 96));
        }
        cout << ANS << "\n";
        return 0;
    }

    int ind = 0;
    while (ind < N) {
        if (ind + 1 < N && S[ind + 1] == '0') {
            if (S[ind] == '1')
                X.push_back("j");
            else
                X.push_back("t");
            ind += 2;
        } else {
            X.push_back(string(1, S[ind]));
            ind++;
        }
    }

    DP.assign(X.size() + 10, -1);
    DP2.assign(X.size() + 10, -1);

    ind = 0;
    string ANS;

    while (ind < (int)X.size()) {
        int OK = ind;
        int NG = (int)X.size() - 1;

        while (NG > OK + 1) {
            int mid = (OK + NG) / 2;
            ll score = calc(mid);

            if (score >= K)
                OK = mid;
            else
                NG = mid;
        }

        K -= calc(OK + 1);
        for (int i = ind; i < OK; i++) {
            if (X[i] == "j" || X[i] == "t")
                ANS += X[i];
            else
                ANS.push_back((char)(stoi(X[i]) + 96));
        }

        ANS.push_back((char)(stoi(X[OK] + X[OK + 1]) + 96));
        ind = OK + 2;

        if (K == 1) {
            for (int i = ind; i < (int)X.size(); i++) {
                if (X[i] == "j" || X[i] == "t")
                    ANS += X[i];
                else
                    ANS.push_back((char)(stoi(X[i]) + 96));
            }
            break;
        }
    }

    cout << ANS << "\n";
    return 0;
}

0