結果

問題 No.3290 Encrypt Failed, but Decrypt Succeeded
ユーザー The Forsaking
提出日時 2025-10-03 21:56:50
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 9 ms / 2,000 ms
コード長 1,062 bytes
コンパイル時間 1,883 ms
コンパイル使用メモリ 195,380 KB
実行使用メモリ 11,856 KB
最終ジャッジ日時 2025-10-03 21:57:07
合計ジャッジ時間 3,180 ms
ジャッジサーバーID
(参考情報)
judge3 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 27
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:15:10: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   15 |     scanf("%s", s + 1);
      |     ~~~~~^~~~~~~~~~~~~

ソースコード

diff #

#include <bits/stdc++.h>

using namespace std;

typedef pair<int, int> pii;
typedef long long ll;
const int N = 2000086, MOD = 998244353, INF = 0x3f3f3f3f;
int n, m, w[N];

ll k;
char s[N];
ll c[N];
int main() {
    cin >> n >> k;
    scanf("%s", s + 1);
    c[n + 1] = 1;
    c[n] = s[n] != '0';
    for (int i = n - 1; i; i--) {
        if (s[i] == '0') continue;
        if (s[i + 1] != '0') c[i] = c[i + 1];
        if ((s[i] - '0') * 10 + (s[i + 1] - '0') <= 26) {
            if (c[i] + c[i + 2] < 2e18) c[i] += c[i + 2];
            else c[i] = 2e18;
        }
    }
    string ans;
    // printf("%lld\n", c[2]);
    for (int i = 1; i < n + 1; i++) {
        if (i != n && s[i] != '0' && (s[i] - '0') * 10 + (s[i + 1] - '0') <= 26) {
            if (k > c[i + 1] || s[i + 1] == '0') {
                k -= c[i + 1];
                ans += 'a' - 1 + (s[i] - '0') * 10 + (s[i + 1] - '0');
                i++;
            } else ans += s[i] - '0' + 'a' - 1;
        } else ans += s[i] - '0' + 'a' - 1;
    }
    printf("%s\n", ans.c_str());
    return 0;
}
0