TLE+WA 0PTS 求调(样例已过)
查看原帖
TLE+WA 0PTS 求调(样例已过)
413370
florence25楼主2023/5/9 22:18

各位大佬走过路过不要错过

#include <bits/stdc++.h>

using namespace std;

const int maxn = 3e4 + 5;
int k, m, cnt, a[maxn];
int ans1[1000005];
priority_queue<long long, vector<long long>, greater<long long> > q;

void read() {
    scanf("%d%d", &k, &m);
    q.push(1);
    while (cnt < k) {
        int u = q.top();
        q.pop();
        a[++ cnt] = u;
        long long u1 = u * 2 + 1;
        long long u2 = u * 4 + 5;
        q.push(u1), q.push(u2);
    }
    int len = 0;
    for (int i = 1; i <= cnt; ++ i) {
        int b[10] = {0};
        int sum = a[i], len1 = 0;
        while (sum) {
            int x = sum % 10;
            b[++ len1] = x;
            sum /= 10;
        }
        for (int j = len1; j >= 1; -- j) {
            ans1[++ len] = b[j];
        }
    }
    for (int i = 1; i <= len; ++ i) printf("%d", ans1[i]);
    printf("\n");
    int l = 1, r = len - (len - m) + 1;
    cnt = 0;
    while (cnt < len - m) {
        int x = 0, k = 0;
        for (int i = l; i <= r; ++ i) {
            if (ans1[i] > x) {
                x = ans1[i];
                k = i;
            }
        }
    //    printf("%d %d %d\n", l, r, x);
        printf("%d", x);
        l = k + 1, r = r + 1;
        cnt ++;
    }
}

int main() {
    read();
    return 0;
}
2023/5/9 22:18
加载中...