QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#468273#8529. Balance of Permutationucup-team3519#WA 3250ms16764kbC++203.3kb2024-07-08 20:04:392024-07-08 20:04:40

Judging History

你现在查看的是最新测评结果

  • [2024-07-08 20:04:40]
  • 评测
  • 测评结果:WA
  • 用时:3250ms
  • 内存:16764kb
  • [2024-07-08 20:04:39]
  • 提交

answer

#include <bits/stdc++.h>

using i128 = __int128_t;

template <typename Tp>
void read(Tp &res) {
    char ch;
    ch = std::cin.get();
    while (!isdigit(ch)) {
        ch = std::cin.get();
    }
    res = 0;
    while (isdigit(ch)) {
        res = res * 10 + int(ch - 48);
        ch = std::cin.get();
    }
}

constexpr int N = 30;
i128 dp[2][N * N / 2 + 19][N][N];

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

    int n, b;
    i128 k;

    read(n), read(b), read(k);

    std::vector<uint8_t> upper(n), lower(n);
    std::vector<int> ans;

    auto check = [&]() -> i128 {
        memset(dp[1], 0, sizeof(dp[1]));
        dp[1][0][0][0] = 1;

        for (int i = 0; i < n; ++i) {
            memset(dp[i & 1], 0, sizeof(dp[i & 1]));
            for (int j = 0; j <= i * i / 2; ++j) {
                for (int a = 0; a <= i; ++a) {
                    for (int b = 0; b <= i; ++b) {
                        if (dp[i & 1 ^ 1][j][a][b] == 0) {
                            continue;
                        }
                        i128 val = dp[i & 1 ^ 1][j][a][b];
                        
                        if (!upper[i] && !lower[i]) {
                            // null
                            dp[i & 1][j + a + b][a][b] += val;

                            // a -= 1 a += 1
                            dp[i & 1][j + a + b][a][b] += a * val;

                            // b -= 1 b += 1
                            dp[i & 1][j + a + b][a][b] += b * val;

                            // a -= 1 b -= 1
                            if (a && b) {
                                dp[i & 1][j + a + b][a - 1][b - 1] += a * b * val;
                            }

                            // a += 1 b += 1
                            dp[i & 1][j + a + b][a + 1][b + 1] += val;
                        } else if (!lower[i]) {
                            dp[i & 1][j + a + b][a + 1][b] += val;
                            if (b) {
                                dp[i & 1][j + a + b][a][b - 1] += b * val;
                            }
                        } else if (!upper[i]) {
                            dp[i & 1][j + a + b][a][b + 1] += val;
                            if (a) {
                                dp[i & 1][j + a + b][a - 1][b] += a * val;
                            }
                        } else {
                            dp[i & 1][j + a + b][a][b] += val;
                        }
                    }
                }
            }
        }

        return dp[(n - 1) & 1][b][0][0];
    };

    for (int i = 0; i < n; ++i) {
        upper[i] = true;
        for (int j = 0; j < n; ++j) {
            if (!lower[j]) {
                int tmp_b = b;
                b -= abs(i - j);
                if (b < 0) {
                    continue;
                }

                lower[j] = true;
                i128 num = check();
                
                if (k <= num) {
                    ans.push_back(j + 1);
                    break;
                }
                b = tmp_b;
                k -= num;
                lower[j] = false;
            }
        }
    }

    for (int i : ans) {
        std::cout << i << ' ';
    }
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 18ms
memory: 16764kb

input:

6 6 6

output:

1 2 6 3 4 5 

result:

ok 6 numbers

Test #2:

score: -100
Wrong Answer
time: 3250ms
memory: 16716kb

input:

30 300 3030303030303030303030

output:

1 2 3 4 9 23 21 12 24 29 26 30 27 22 20 17 10 25 28 15 19 13 7 14 6 8 5 18 16 11 

result:

wrong answer 7th numbers differ - expected: '20', found: '21'