QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#280409#7778. Turning Permutationucup-team1469#WA 1ms3512kbC++174.5kb2023-12-09 15:52:312023-12-09 15:52:31

Judging History

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

  • [2023-12-09 15:52:31]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:3512kb
  • [2023-12-09 15:52:31]
  • 提交

answer

#ifndef LOCAL
#define FAST_IO
#endif

// ============
#include <algorithm>
#include <array>
#include <bitset>
#include <cassert>
#include <cmath>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>

#define OVERRIDE(a, b, c, d, ...) d
#define REP2(i, n) for (i32 i = 0; i < (i32)(n); ++i)
#define REP3(i, m, n) for (i32 i = (i32)(m); i < (i32)(n); ++i)
#define REP(...) OVERRIDE(__VA_ARGS__, REP3, REP2)(__VA_ARGS__)
#define PER(i, n) for (i32 i = (i32)(n) - 1; i >= 0; --i)
#define ALL(x) begin(x), end(x)

using namespace std;

using u32 = unsigned int;
using u64 = unsigned long long;
using i32 = signed int;
using i64 = signed long long;
using f64 = double;
using f80 = long double;

template <typename T>
using Vec = vector<T>;

template <typename T>
bool chmin(T &x, const T &y) {
    if (x > y) {
        x = y;
        return true;
    }
    return false;
}
template <typename T>
bool chmax(T &x, const T &y) {
    if (x < y) {
        x = y;
        return true;
    }
    return false;
}

#ifdef INT128

using u128 = __uint128_t;
using i128 = __int128_t;

istream &operator>>(istream &is, i128 &x) {
    i64 v;
    is >> v;
    x = v;
    return is;
}
ostream &operator<<(ostream &os, i128 x) {
    os << (i64)x;
    return os;
}
istream &operator>>(istream &is, u128 &x) {
    u64 v;
    is >> v;
    x = v;
    return is;
}
ostream &operator<<(ostream &os, u128 x) {
    os << (u64)x;
    return os;
}

#endif

[[maybe_unused]] constexpr i32 INF = 1000000100;
[[maybe_unused]] constexpr i64 INF64 = 3000000000000000100;
struct SetUpIO {
    SetUpIO() {
#ifdef FAST_IO
        ios::sync_with_stdio(false);
        cin.tie(nullptr);
#endif
        cout << fixed << setprecision(15);
    }
} set_up_io;
// ============

#ifdef DEBUGF
#else
#define DBG(x) (void) 0
#endif

i64 mul(i64 x, i64 y) {
    if (x > INF64 / y) {
        return INF64;
    }
    return x * y;
}

int main() {
    i32 n;
    i64 k;
    cin >> n >> k;
    --k;
    
    Vec<Vec<i64>> binom(n + 1, Vec<i64>(n + 1, 0));
    binom[0][0] = 1;
    REP(i, n) REP(j, i + 1) {
        binom[i + 1][j] += binom[i][j];
        binom[i + 1][j + 1] += binom[i][j];
    }
    
    Vec<Vec<Vec<i64>>> dp(2, Vec<Vec<i64>>(n + 1, Vec<i64>(n, 0)));
    dp[0][1][0] = 1;
    dp[1][1][0] = 1;
    REP(i, 2, n + 1) {
        REP(j, n) {
            REP(k, j + 1, i) {
                dp[0][i][j] += dp[1][i - 1][k - 1];
                chmin(dp[0][i][j], INF64);
            }
            REP(k, j) {
                dp[1][i][j] += dp[0][i - 1][k];
                chmin(dp[1][i][j], INF64);
            }
        }
    }
    DBG(dp);
    
    Vec<i64> cnt(n + 1, 0);
    cnt[1] = 1;
    REP(i, 2, n + 1) {
        REP(j, i) {
            cnt[i] += dp[0][i][j];
            chmin(cnt[i], INF64);
            cnt[i] += dp[1][i][j];
            chmin(cnt[i], INF64);
        }
    }
    DBG(cnt);
    
    auto calc = [&](const Vec<i32> &p) -> i64 {
        Vec<i32> lens;
        REP(i, n) {
            if (p[i] == -1 && (i == 0 || p[i - 1] != -1)) {
                i32 j = i;
                while (j < n && p[j] == -1) {
                    ++j;
                }
                lens.push_back(j - i);
            }
        }
        REP(i, lens.size()) {
            if (i != 0 && i != (i32)lens.size() - 1 && lens[i] % 2 == 0) {
                return 0;
            }
        }
        i64 ans = 1;
        for (i32 l : lens) {
            if (l >= 2) {
                ans = mul(ans, cnt[l] / 2);
            }
        }
        i32 c = 0;
        for (i32 l : lens) {
            ans = mul(ans, binom[c + l][l]);
            c += l;
        }
        return ans;
    };
    
    if (k >= cnt[n]) {
        cout << -1 << '\n';
        exit(0);
    }
    
    Vec<i32> p(n, -1);
    Vec<i32> ans;
    REP(i, n) {
        REP(j, n) {
            if (p[j] != -1) {
                continue;
            }
            p[j] = i;
            i64 c = calc(p);
            if (c > k) {
                ans.push_back(j);
                break;
            } else {
                k -= c;
                p[j] = -1;
            }
        }
    }
    REP(i, n) {
        cout << ans[i] + 1 << " \n"[i + 1 == n];
    }
}

詳細信息

Test #1:

score: 100
Accepted
time: 1ms
memory: 3448kb

input:

3 2

output:

2 1 3

result:

ok 3 number(s): "2 1 3"

Test #2:

score: 0
Accepted
time: 0ms
memory: 3448kb

input:

3 5

output:

-1

result:

ok 1 number(s): "-1"

Test #3:

score: 0
Accepted
time: 0ms
memory: 3472kb

input:

4 6

output:

3 1 2 4

result:

ok 4 number(s): "3 1 2 4"

Test #4:

score: 0
Accepted
time: 0ms
memory: 3512kb

input:

4 11

output:

-1

result:

ok 1 number(s): "-1"

Test #5:

score: -100
Wrong Answer
time: 0ms
memory: 3448kb

input:

3 1

output:

1 2 3

result:

wrong answer 2nd numbers differ - expected: '3', found: '2'