100702024-03-26 11:23:56Error42Kígyózó szavakcpp17Elfogadva 100/10052ms4644 KiB
#include <climits>
#include <iostream>
#include <vector>

using namespace std;

using ll = long long;

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

    ll h, n;
    cin >> h >> n;

    vector<vector<ll>> dp(h, vector<ll>(26, 0));

    for (int j = 0; j < 26; j++)
        dp[0][j] = 1;

    for (int i = 1; i < h; i++) {
        dp[i][0] = dp[i - 1][1] + 1;

        for (int j = 1; j < 25; j++)
            dp[i][j] = min((ll)INT_MAX, dp[i - 1][j - 1] + dp[i - 1][j + 1]) + 1;

        dp[i][25] = dp[i - 1][24] + 1;
    }

    while (n--) {
        ll k;
        cin >> k;

        string s = "";

        // first character
        int last = 0;

        while (dp[h - 1][last] < k) {
            k -= dp[h - 1][last];
            last++;
        }

        s.push_back('a' + last);

        for (int i = h - 2; i >= 0; i--) {
            if (k == 1)
                break;
            k--;

            vector<int> continuations;
            if (last > 0)
                continuations.push_back(last - 1);
            if (last < 25)
                continuations.push_back(last + 1);

            for (int j : continuations) {
                if (dp[i][j] >= k) {
                    s.push_back('a' + j);
                    last = j;
                    break;
                }

                k -= dp[i][j];
            }
        }

        cout << s << "\n";
    }
}
RészfeladatÖsszpontTesztVerdiktIdőMemória
base100/100
1Elfogadva0/03ms1828 KiB
2Elfogadva0/03ms2020 KiB
3Elfogadva5/53ms2248 KiB
4Elfogadva5/53ms2440 KiB
5Elfogadva5/53ms2672 KiB
6Elfogadva5/53ms2744 KiB
7Elfogadva5/53ms3012 KiB
8Elfogadva5/54ms3092 KiB
9Elfogadva5/521ms3380 KiB
10Elfogadva5/517ms3348 KiB
11Elfogadva5/527ms3664 KiB
12Elfogadva5/528ms3684 KiB
13Elfogadva5/552ms4164 KiB
14Elfogadva6/613ms4024 KiB
15Elfogadva6/627ms4232 KiB
16Elfogadva6/617ms4276 KiB
17Elfogadva6/614ms4148 KiB
18Elfogadva7/717ms4256 KiB
19Elfogadva7/750ms4644 KiB
20Elfogadva7/718ms4336 KiB