100632024-03-25 21:00:23szilKígyózó szavakcpp17Accepted 100/1008ms3880 KiB
#include <bits/stdc++.h>

using ll = long long;
using namespace std;

const ll INF = 1e10;

int h, t;
ll cnt[1001][26];

void solve() {
    ll k; cin >> k;
    string ans;
    while (k >= 1) {
        for (int i = 0; i < 26; i++) {
            if (!ans.empty() && abs(i-(ans.back()-'a')) != 1) continue;
            if (cnt[h-ans.size()][i] >= k) {
                ans += char('a'+i);
                k--;
                break;
            } else {
                k -= cnt[h-ans.size()][i];
            }
        }
    }
    cout << ans << "\n";
}

int main() {
    ios_base::sync_with_stdio(0); cin.tie(0);
    cin >> h >> t;
    for (int i = 1; i <= h; i++) {
        for (int j = 0; j < 26; j++) {
            cnt[i][j] = 1;
            if (j != 0) cnt[i][j] += cnt[i-1][j-1];
            if (j != 25) cnt[i][j] += cnt[i-1][j+1];
            cnt[i][j] = min(cnt[i][j], INF);
        }
    }
    while (t--) {
        solve();
    }
    return 0;
}
SubtaskSumTestVerdictTimeMemory
base100/100
1Accepted0/03ms1832 KiB
2Accepted0/03ms2052 KiB
3Accepted5/53ms2264 KiB
4Accepted5/53ms2444 KiB
5Accepted5/53ms2660 KiB
6Accepted5/53ms2872 KiB
7Accepted5/53ms2968 KiB
8Accepted5/53ms3092 KiB
9Accepted5/56ms3452 KiB
10Accepted5/54ms3420 KiB
11Accepted5/56ms3492 KiB
12Accepted5/56ms3508 KiB
13Accepted5/58ms3768 KiB
14Accepted6/64ms3376 KiB
15Accepted6/66ms3720 KiB
16Accepted6/64ms3636 KiB
17Accepted6/64ms3612 KiB
18Accepted7/74ms3628 KiB
19Accepted7/78ms3880 KiB
20Accepted7/74ms3652 KiB