100612024-03-25 20:58:11szilKígyózó szavakcpp17Wrong answer 30/1003ms4260 KiB
#include <bits/stdc++.h>

using ll = long long;
using namespace std;

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

void solve() {
    int 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];
        }
    }
    while (t--) {
        solve();
    }
    return 0;
}
SubtaskSumTestVerdictTimeMemory
base30/100
1Accepted0/03ms2108 KiB
2Accepted0/03ms2232 KiB
3Accepted5/53ms2356 KiB
4Accepted5/53ms2444 KiB
5Accepted5/53ms2536 KiB
6Accepted5/53ms2668 KiB
7Accepted5/53ms2760 KiB
8Accepted5/53ms3096 KiB
9Wrong answer0/53ms3052 KiB
10Wrong answer0/53ms3056 KiB
11Wrong answer0/53ms3224 KiB
12Wrong answer0/53ms3484 KiB
13Wrong answer0/53ms4076 KiB
14Wrong answer0/63ms3508 KiB
15Wrong answer0/63ms3732 KiB
16Wrong answer0/63ms3616 KiB
17Wrong answer0/63ms3900 KiB
18Wrong answer0/73ms3872 KiB
19Wrong answer0/73ms4260 KiB
20Wrong answer0/73ms3928 KiB