QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#181125#6353. Kth Lex Min Min Min Subpalindromesucup-team859#WA 133ms11044kbC++174.2kb2023-09-16 15:57:172023-09-16 15:57:18

Judging History

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

  • [2023-09-16 15:57:18]
  • 评测
  • 测评结果:WA
  • 用时:133ms
  • 内存:11044kb
  • [2023-09-16 15:57:17]
  • 提交

answer

#include <bits/stdc++.h>

#define lsb(x) (x & (-x))

using ull = unsigned long long;
using ll = long long;

using namespace std;

constexpr ll INF = 2e18;

inline ll mul(ll a, ll b) {
    if (INF / b <= a) {
        return INF;
    }
    return a * b;
}

inline ll logpow(ll a, ll b) {
    ll result = 1;
    while (b > 0) {
        if (b & 1) result = mul(a, result);
        b >>= 1;
        a = mul(a, a);
    }
    return result;
}

int main() {
#ifdef HOME
    ifstream cin("input.in");
    ofstream cout("output.out");
#endif
    ios::sync_with_stdio(false);
    cin.tie(0), cout.tie(0);

    int n, m;
    ll k;
    cin >> n >> m >> k;

    if (m == 1) {
        if (k > 1) {
            cout << -1;
            return 0;
        }
        for (int i = 1; i <= n; i++) {
            cout << 1 << " "; 
        }
        return 0;
    }

    if (m == 2) {
        vector<string> strings;
        int result = (int) 1e9;

        auto Get = [](string str) {
            int n = (int)str.size();
            int cnt = n;

            for (int i = 0; i < n; i++) {
                if (i + 1 < n && str[i] == str[i + 1]) {
                    cnt++;
                }
                if (i + 2 < n && str[i] == str[i + 2]) {
                    cnt++;
                }
                if (i + 3 < n && str[i] == str[i + 3] && str[i + 1] == str[i + 2]) {
                    cnt++;
                }
            }
            return cnt;
        };

        for (char first = '1'; first <= '2'; first++) {
            char second = '1' - first + '2';
            for (int x = 1; x <= 2; x++) {
                for (int y = 1; y <= 2; y++) {
                    
                    int pos = 0;
                    string str;

                    auto Add = [n](string& str, char ch, int len) {
                        while ((int)str.size() < n && len > 0) {
                            len--;
                            str += ch;
                        }
                    };

                    while ((int)str.size() < n) {
                        if (pos % 4 == 0) {
                            Add(str, first, x);
                        } else if (pos % 4 == 1) {
                            Add(str, second, y);
                        } else if (pos % 4 == 2) {
                            Add(str, first, 3 - x);
                        } else {
                            Add(str, second, 3 - y);
                        }
                        pos++;
                    }

                    

                    int cnt = Get(str);
                    if (cnt < result) {
                        result = cnt;
                        strings.clear();
                    }

                    if (cnt <= result) {
                        strings.push_back(str);
                    }
                }
            }
        }
        
        sort(strings.begin(), strings.end());
        strings.resize(unique(strings.begin(), strings.end()) - strings.begin());

        // for (auto itr : strings) {
        //     cerr << itr << " " << Get(itr) << "\n";
        // }

        if ((int)strings.size() < k) {
            cout << -1;
        } else {
            for (auto itr : strings[k - 1]) {
                cout << itr << " ";
            }
        }
        return 0;
    }

    ll total = mul(m, mul(m - 1, logpow(m - 2, n - 2)));
    if (total < k) {
        cout << -1;
        return 0;
    }

    vector<ll> v(n);

    ll coef0 = mul(m - 1, logpow(m - 2, n - 2));
    ll v0 = (k - 1) / coef0 + 1;
    k -= (v0 - 1) * coef0;
    v[0] = v0;

    ll coef1 = logpow(m - 2, n - 2);
    ll v1 = (k - 1) / coef1 + 1;
    k -= (v1 - 1) * coef1;
    v[1] = (v1 < v0 ? v1 : v1 + 1);
    
    for (int i = 2; i < n; i++) {
        ll coef = logpow(m - 2, n - i - 1);
        ll vi = (k - 1) / coef + 1;
        k -= (vi - 1) * coef;
        
        if (vi >= min(v[i - 1], v[i - 2])) {
            vi++;
        }
        if (vi >= max(v[i - 1], v[i - 2])) {
            vi++;
        }
        v[i] = vi;
    }

    for (auto itr : v) {
        cout << itr << " ";
    }

    return 0;
}

详细

Test #1:

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

input:

1 1 1

output:

1 

result:

ok 1 number(s): "1"

Test #2:

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

input:

2 2 2

output:

2 1 

result:

ok 2 number(s): "2 1"

Test #3:

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

input:

3 3 3

output:

2 1 3 

result:

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

Test #4:

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

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: 3844kb

input:

10 7 998244353

output:

-1

result:

ok 1 number(s): "-1"

Test #6:

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

input:

3 1000 994253860

output:

998 244 353 

result:

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

Test #7:

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

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: 3544kb

input:

58 4 864691128455135233

output:

-1

result:

ok 1 number(s): "-1"

Test #9:

score: 0
Accepted
time: 133ms
memory: 10848kb

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: 132ms
memory: 11044kb

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: 3604kb

input:

1 1 2

output:

-1

result:

ok 1 number(s): "-1"

Test #12:

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

input:

1 2 2

output:

2 

result:

ok 1 number(s): "2"

Test #13:

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

input:

2 2 1

output:

1 2 

result:

ok 2 number(s): "1 2"

Test #14:

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

input:

3 2 4

output:

2 1 1 

result:

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

Test #15:

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

input:

3 2 7

output:

-1

result:

ok 1 number(s): "-1"

Test #16:

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

input:

4 2 10

output:

-1

result:

wrong answer 1st numbers differ - expected: '2', found: '-1'