QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#240566#6353. Kth Lex Min Min Min Subpalindromesjzh#WA 117ms11028kbC++205.6kb2023-11-05 16:26:382023-11-05 16:26:38

Judging History

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

  • [2023-11-05 16:26:38]
  • 评测
  • 测评结果:WA
  • 用时:117ms
  • 内存:11028kb
  • [2023-11-05 16:26:38]
  • 提交

answer

#include <bits/stdc++.h>

using namespace std;

using ll = unsigned long long;

constexpr ll mx = ULONG_LONG_MAX;

ll mul(ll a, ll b) {
    if(a>mx/b) return mx;
    return  a*b;
}

ll qpow(ll a, ll b) {
    ll ans = 1;
    while(b) {
        if(b&1) {
            ans = mul(ans, a);
        }
        a = mul(a, a);
        b/=2;
    }
    return ans;
}

struct info{
    vector<int>vec;
    int last;

    explicit info(vector<int>temp) {
        vec = temp;
        last = 0;
        for(int i = 2 ; i < temp.size() ; i ++) {
            bool flag = true;
            for(int j = temp.size() - i, k = temp.size()-1 ; j < k ; j ++, k--){
                if(temp[j]!=temp[k]) flag = false;
            }
            if(flag) {
                last = i;
                break;
            }
        }
        assert(last!=0);
    }

    void advance(){
        int cnt0 = 0, cnt1 = 0;
        if(vec.back()==0) cnt0++;
        else cnt1++;
        if(*prev(end(vec), 2)==0) cnt0++;
        else cnt1++;
        if(*prev(end(vec), last+1)==0) cnt0++;
        else cnt1++;

        if(cnt0<cnt1) {
            if(vec.back()==0) {
                last = 2;
            }
            else if(*prev(end(vec), 2)==0) {
                last = 3;
            }
            else{
                last += 2;
            }
            vec.push_back(0);
        }
        else{
            if(vec.back()==1) {
                last = 2;
            }
            else if(*prev(end(vec), 2)==1) {
                last = 3;
            }
            else{
                last += 2;
            }
            vec.push_back(1);
        }
        assert(last!=vec.size());
    }
};

void solve() {
    ll n, m, k; cin>>n >>m >>k;

    if(n==1) {
        if(k<=m) cout << k << endl;
        else cout << -1 << endl;
        return;
    }
    if(n==2) {
        if(m *(m-1) >= k) {
            k--;
            ll a = k / (m-1) + 1;
            ll b = k % (m-1) + 1;
            if(b>=a) b ++;
            cout << a << ' ' << b << endl;
        }
        else{
            cout << -1 << endl;
        }
        return;
    }

    if(m==1){
        if(k==1) {
            for(int i = 0 ; i < n ; i ++) cout << 1 << ' '; cout << endl;
            return;
        }
        else{
            cout << "-1" << endl;
            return;
        }
    }
    else if(m==2) {
        if(n<=15) {
            set<vector<int>>all;
            auto calc = [&](vector<int>vec) {
                int ans = 0;
                for(int i = 0 ; i < n ; i ++) {
                    for(int j = i ; j < n ; j ++){
                        bool flag = true;
                        for(int k = i ; i+j-k > k ; k ++) {
                            if(vec[k]!=vec[i+j-k]) flag = false;
                        }
                        ans += flag;
                    }
                }
                return ans;
            };

            vector<int>temp(n);
            for(int st = 0 ; st < (1<<n) ; st ++) {
                for(int i = 0 ; i < n ; i ++) {
                    temp[i] = (st>>i&1);
                }
                if(calc(temp)==2*n-2) all.insert(temp);
                assert(calc(temp)>=2*n-2);
            }
            if(all.size()<k) {
                cout << "-1\n";
                return;
            }

            auto vec = *next(begin(all), k-1);
            for(auto &v: vec) cout << v << ' '; cout << endl;
            return;
        }
        else{
            assert(false);
            if(k>12) {
                cout << "-1" << endl;
                return;
            }
            int len = 10;
            vector<info>all;
            auto calc = [&](vector<int>vec) {
                int ans = 0;
                for(int i = 0 ; i < len ; i ++) {
                    for(int j = i ; j < len ; j ++){
                        bool flag = true;
                        for(int k = i ; i+j-k > k ; k ++) {
                            if(vec[k]!=vec[i+j-k]) flag = false;
                        }
                        ans += flag;
                    }
                }
                return ans;
            };

            vector<int>temp(len);
            for(int st = 0 ; st < (1<<len) ; st ++) {
                for(int i = 0 ; i < len ; i ++) {
                    temp[i] = (st>>i&1);
                }
                if(calc(temp)==2*len-2) all.emplace_back(info(temp));
            }
            for(int i = len ; i < n ; i ++) {
                for(auto &it: all) it.advance();
            }

            set<vector<int>>st;
            for(auto &it: all) st.insert(it.vec);

            auto vec = *next(begin(st), k-1);
            for(auto &v: vec) cout << v <<' '; cout<< endl;
            return;
        }
    }
    else{
        if( mul(mul(m, (m-1)),qpow(m-2, n-2)) < k) {
            cout << "-1\n";
            return;
        }
        k--;
        vector<ll>ans(n);
        ll sz2 = qpow(m-2, n-2), sz1 = sz2 * (m-1);
        ans[0] = k / sz1 + 1;
        k -= (k/sz1) * sz1;
        ans[1] = k / sz2 + 1;
        k -= (k/sz2) *sz2;
        if(ans[1]>=ans[0]) ans[1] ++;

        for(int i = 2 ; i < n ; i ++){
            sz2 = qpow(m-2, n-i-1);
            ans[i] = k / sz2 + 1;
            if(ans[i]>=min(ans[i-1], ans[i-2])) ans[i]++;
            if(ans[i]>=max(ans[i-1], ans[i-2])) ans[i]++;
            k -= (k/sz2) *sz2;
        }
        for(int i = 0 ; i < n ; i ++)cout <<ans[i] << ' '; cout <<endl;
    }
}

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

    solve();

    return 0;
}

詳細信息

Test #1:

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

input:

1 1 1

output:

1

result:

ok 1 number(s): "1"

Test #2:

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

input:

2 2 2

output:

2 1

result:

ok 2 number(s): "2 1"

Test #3:

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

input:

3 3 3

output:

2 1 3 

result:

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

Test #4:

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

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

input:

10 7 998244353

output:

-1

result:

ok 1 number(s): "-1"

Test #6:

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

input:

3 1000 994253860

output:

998 244 353 

result:

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

Test #7:

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

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

input:

58 4 864691128455135233

output:

-1

result:

ok 1 number(s): "-1"

Test #9:

score: 0
Accepted
time: 117ms
memory: 11028kb

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: 104ms
memory: 11008kb

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: 1ms
memory: 3400kb

input:

1 1 2

output:

-1

result:

ok 1 number(s): "-1"

Test #12:

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

input:

1 2 2

output:

2

result:

ok 1 number(s): "2"

Test #13:

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

input:

2 2 1

output:

1 2

result:

ok 2 number(s): "1 2"

Test #14:

score: -100
Wrong Answer
time: 1ms
memory: 3488kb

input:

3 2 4

output:

1 0 0 

result:

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