QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#305946#6353. Kth Lex Min Min Min SubpalindromesckisekiAC ✓180ms218640kbC++203.3kb2024-01-16 06:24:032024-01-16 06:24:04

Judging History

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

  • [2024-01-16 06:24:04]
  • 评测
  • 测评结果:AC
  • 用时:180ms
  • 内存:218640kb
  • [2024-01-16 06:24:03]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;

#ifdef CKISEKI
#define safe cerr << __PRETTY_FUNCTION__ << " line " << __LINE__ << " safe\n"
#define debug(a...) debug_(#a, a)
#define orange(a...) orange_(#a, a)
template <typename ...T>
void debug_(const char *s, T ...a) {
    cerr << "\e[1;32m( " << s << " ) = ( ";
    int cnt = sizeof...(T);
    (..., (cerr << a << (--cnt ? ", " : " )\e[0m\n")));
}
template <typename I>
void orange_(const char *s, I L, I R) {
    cerr << "\e[1;32m[ " << s << " ] = [ ";
    for (int f = 0; L != R; ++L)
        cerr << (f++ ? ", " : "") << *L;
    cerr << " ]\e[0m\n";
}
#else
#define safe ((void)0)
#define debug(a...) safe
#define orange(a...) safe
#endif

const int maxn = 1000025;
const int64_t INF = int64_t(1e18) + 25;

int64_t suf_prod[maxn];
int ans[maxn];
void f(int n, int i, int64_t k, vector<int> banned) {
    if (i == n) {
        return;
    }
    int64_t c = k / suf_prod[i + 1];
    int num = c;
    for (int x: set<int>(banned.begin(), banned.end()))
        if (x <= num) {
            ++num;
        }
    ans[i] = num;
    banned.push_back(num);
    if (banned.size() == 3) {
        banned = vector<int>(banned.begin() + 1, banned.end());
    }

    f(n, i + 1, k % suf_prod[i + 1], banned);
}

int64_t Mul(int64_t a, int64_t b) {
    if (a <= (INF + b - 1) / b) {
        return min(a * b, INF);
    } else {
        return INF;
    }
}

bool valid(vector<int> a) {
    auto b = a;
    reverse(b.begin(), b.end());
    return a == b;
}

vector<vector<int>> brute(int n) {
    const int n2 = 1 << n;
    vector<pair<int, vector<int>>> res;
    for (int i = 0; i < n2; ++i) {
        int an = 0;
        vector<int> a;
        for (int j = 0; j < n; ++j) {
            vector<int> b;
            for (int k = j; k < n; ++k) {
                b.push_back((i >> k) & 1);
                if (valid(b)) an++;
            }
            a.push_back((i >> j) & 1);
        }
        res.emplace_back(an, a);
    }
    vector<vector<int>> ret;
    sort(res.begin(), res.end());
    int v = res[0].first;
    for (auto [P, a] : res) {
        if (P != v) continue;
        ret.push_back(a);
    }
    return ret;
}

int main() {
    cin.tie(nullptr)->sync_with_stdio(false);
    int n, m;
    int64_t k;
    cin >> n >> m >> k;

    if (m == 1) {
        if (k == 1) {
            for (int i = 0; i < n; i++)
                cout << 1 << (i+1==n ? '\n' : ' ');
        } else {
            cout << -1 << '\n';
        }
        return 0;
    }

    if (m == 2) {
        auto s = brute(min(n, 6));
        if (k > s.size()) {
            cout << -1 << '\n';
        } else {
            auto a = s[k - 1];
            for (int i = 0; i < n; i++) {
                cout << a[i % 6] + 1 << (i+1==n ? '\n' : ' ');
            }
        }
        return 0;
    }

    suf_prod[0] = m;
    suf_prod[1] = m - 1;
    for (int i = 2; i < n; i++) {
        suf_prod[i] = m - 2;
    }
    suf_prod[n] = 1;

    for (int i = n - 1; i >= 0; i--) {
        suf_prod[i] = Mul(suf_prod[i + 1], suf_prod[i]);
    }

    if (suf_prod[0] < k) {
        cout << -1 << '\n';
        return 0;
    }

    f(n, 0, k - 1, {});

    for (int i = 0; i < n; i++) {
        cout << ans[i] + 1 << (i+1==n ? '\n' : ' ');
    }

    return 0;
}

详细

Test #1:

score: 100
Accepted
time: 0ms
memory: 3572kb

input:

1 1 1

output:

1

result:

ok 1 number(s): "1"

Test #2:

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

input:

2 2 2

output:

2 1

result:

ok 2 number(s): "2 1"

Test #3:

score: 0
Accepted
time: 1ms
memory: 5620kb

input:

3 3 3

output:

2 1 3

result:

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

Test #4:

score: 0
Accepted
time: 1ms
memory: 5692kb

input:

9 9 8244353

output:

2 4 1 2 6 8 1 2 7

result:

ok 9 numbers

Test #5:

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

input:

10 7 998244353

output:

-1

result:

ok 1 number(s): "-1"

Test #6:

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

input:

3 1000 994253860

output:

998 244 353

result:

ok 3 number(s): "998 244 353"

Test #7:

score: 0
Accepted
time: 1ms
memory: 5576kb

input:

58 4 864691128455135232

output:

4 3 2 4 3 2 4 3 2 4 3 2 4 3 2 4 3 2 4 3 2 4 3 2 4 3 2 4 3 2 4 3 2 4 3 2 4 3 2 4 3 2 4 3 2 4 3 2 4 3 2 4 3 2 4 3 2 4

result:

ok 58 numbers

Test #8:

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

input:

58 4 864691128455135233

output:

-1

result:

ok 1 number(s): "-1"

Test #9:

score: 0
Accepted
time: 180ms
memory: 218476kb

input:

1000000 1000000 1000000000000000000

output:

1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 ...

result:

ok 1000000 numbers

Test #10:

score: 0
Accepted
time: 164ms
memory: 218620kb

input:

1000000 4 1000000000000000000

output:

1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 ...

result:

ok 1000000 numbers

Test #11:

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

input:

1 1 2

output:

-1

result:

ok 1 number(s): "-1"

Test #12:

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

input:

1 2 2

output:

2

result:

ok 1 number(s): "2"

Test #13:

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

input:

2 2 1

output:

1 2

result:

ok 2 number(s): "1 2"

Test #14:

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

input:

3 2 4

output:

2 1 1

result:

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

Test #15:

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

input:

3 2 7

output:

-1

result:

ok 1 number(s): "-1"

Test #16:

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

input:

4 2 10

output:

2 2 1 2

result:

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

Test #17:

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

input:

4 2 3

output:

1 2 1 1

result:

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

Test #18:

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

input:

5 2 7

output:

2 1 1 2 1

result:

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

Test #19:

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

input:

5 2 13

output:

-1

result:

ok 1 number(s): "-1"

Test #20:

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

input:

6 2 5

output:

1 2 2 1 1 2

result:

ok 6 numbers

Test #21:

score: 0
Accepted
time: 30ms
memory: 3844kb

input:

1000000 2 3

output:

1 2 1 1 2 2 1 2 1 1 2 2 1 2 1 1 2 2 1 2 1 1 2 2 1 2 1 1 2 2 1 2 1 1 2 2 1 2 1 1 2 2 1 2 1 1 2 2 1 2 1 1 2 2 1 2 1 1 2 2 1 2 1 1 2 2 1 2 1 1 2 2 1 2 1 1 2 2 1 2 1 1 2 2 1 2 1 1 2 2 1 2 1 1 2 2 1 2 1 1 2 2 1 2 1 1 2 2 1 2 1 1 2 2 1 2 1 1 2 2 1 2 1 1 2 2 1 2 1 1 2 2 1 2 1 1 2 2 1 2 1 1 2 2 1 2 1 1 2 2 ...

result:

ok 1000000 numbers

Test #22:

score: 0
Accepted
time: 26ms
memory: 3528kb

input:

1000000 2 5

output:

1 2 2 1 1 2 1 2 2 1 1 2 1 2 2 1 1 2 1 2 2 1 1 2 1 2 2 1 1 2 1 2 2 1 1 2 1 2 2 1 1 2 1 2 2 1 1 2 1 2 2 1 1 2 1 2 2 1 1 2 1 2 2 1 1 2 1 2 2 1 1 2 1 2 2 1 1 2 1 2 2 1 1 2 1 2 2 1 1 2 1 2 2 1 1 2 1 2 2 1 1 2 1 2 2 1 1 2 1 2 2 1 1 2 1 2 2 1 1 2 1 2 2 1 1 2 1 2 2 1 1 2 1 2 2 1 1 2 1 2 2 1 1 2 1 2 2 1 1 2 ...

result:

ok 1000000 numbers

Test #23:

score: 0
Accepted
time: 26ms
memory: 3672kb

input:

1000000 2 7

output:

2 1 1 2 1 2 2 1 1 2 1 2 2 1 1 2 1 2 2 1 1 2 1 2 2 1 1 2 1 2 2 1 1 2 1 2 2 1 1 2 1 2 2 1 1 2 1 2 2 1 1 2 1 2 2 1 1 2 1 2 2 1 1 2 1 2 2 1 1 2 1 2 2 1 1 2 1 2 2 1 1 2 1 2 2 1 1 2 1 2 2 1 1 2 1 2 2 1 1 2 1 2 2 1 1 2 1 2 2 1 1 2 1 2 2 1 1 2 1 2 2 1 1 2 1 2 2 1 1 2 1 2 2 1 1 2 1 2 2 1 1 2 1 2 2 1 1 2 1 2 ...

result:

ok 1000000 numbers

Test #24:

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

input:

1000000 2 1000000000000000000

output:

-1

result:

ok 1 number(s): "-1"

Test #25:

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

input:

1 3 2

output:

2

result:

ok 1 number(s): "2"

Test #26:

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

input:

2 3 5

output:

3 1

result:

ok 2 number(s): "3 1"

Test #27:

score: 0
Accepted
time: 170ms
memory: 218640kb

input:

1000000 3 5

output:

3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 ...

result:

ok 1000000 numbers

Test #28:

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

input:

1000000 3 7

output:

-1

result:

ok 1 number(s): "-1"

Test #29:

score: 0
Accepted
time: 144ms
memory: 218460kb

input:

1000000 4 211106232532991

output:

1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 ...

result:

ok 1000000 numbers

Test #30:

score: 0
Accepted
time: 168ms
memory: 218412kb

input:

1000000 5 1000000000000000000

output:

1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 ...

result:

ok 1000000 numbers

Test #31:

score: 0
Accepted
time: 170ms
memory: 218496kb

input:

1000000 123123 1000000000000000000

output:

1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 ...

result:

ok 1000000 numbers

Test #32:

score: 0
Accepted
time: 1ms
memory: 5624kb

input:

6 1000000 1000000000000000000

output:

1 2 4 9 15 8

result:

ok 6 numbers

Test #33:

score: 0
Accepted
time: 1ms
memory: 5668kb

input:

4 1000000 1000000000000000000

output:

2 7 15 9

result:

ok 4 number(s): "2 7 15 9"

Test #34:

score: 0
Accepted
time: 1ms
memory: 5640kb

input:

3 1000000 999997000002000000

output:

1000000 999999 999998

result:

ok 3 number(s): "1000000 999999 999998"

Test #35:

score: 0
Accepted
time: 1ms
memory: 5884kb

input:

3 1000000 999997000002000001

output:

-1

result:

ok 1 number(s): "-1"