QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#99712#6353. Kth Lex Min Min Min Subpalindromeswhatever#WA 70ms15168kbC++172.1kb2023-04-23 15:32:592023-04-23 15:33:03

Judging History

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

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2023-04-23 15:33:03]
  • 评测
  • 测评结果:WA
  • 用时:70ms
  • 内存:15168kb
  • [2023-04-23 15:32:59]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;
#define rep(i, a, b) for (int i = a, I = b; i <= I; ++i)
#define per(i, a, b) for (int i = a, I = b; i >= I; --i)
using i64 = long long;
using i128 = __int128_t;
using pii = pair<i64, i64>;
template<typename T> void up(T &x, T y) { if (x < y) x = y; }
template<typename T> void down(T &x, T y) { if (x > y) x = y; }

const int N = 1000005;
int n, m, a[N], cnt;
i64 k, ways[N];

bool check(int rp) {
    int cnt = 0;
    rep(lp, max(1, rp - 6), rp - 1) {
        bool flag = true;
        rep(i, lp, (lp + rp) / 2) flag &= (a[i] == a[lp + rp - i]);
        cnt += flag;
        if (cnt > (rp > 2)) return false; 
    }
    return true;
}
void dfs(int cur) {
    if (cur == n + 1) {
        if (++cnt == k) {
            rep(i, 1, n) cout << a[i] << " \n"[i == n];
            exit(0);
        }
        return;
    }
    rep(i, 1, 2) {
        a[cur] = i;
        if (check(cur)) dfs(cur + 1);
    }
}

i64 mul(i64 x, i64 y) {
    return min(i128(2e18), i128(x) * y);
}
int get_rank(int i, int x) {
    if (x == a[i - 1] || (i > 1 && x == a[i - 2])) return -1;
    int res = x;
    if (i > 1) res -= (x > a[i - 1]);
    if (i > 2) res -= (x > a[i - 2]);
    return res;
}

int main() {
    ios::sync_with_stdio(0), cin.tie(0);

    cin >> n >> m >> k;
    
    if (m == 1) {
        if (k > 1) {
            cout << "-1\n";
            return 0;
        }
        rep(i, 1, n) cout << 1 << " \n"[i == n];
        return 0;
    }
    if (m == 2) {
        dfs(1);
        cout << "-1\n";
        return 0;
    }
    
    ways[0] = 1;
    rep(i, 1, n - 2) ways[i] = mul(ways[i - 1], m - 2);
    ways[n - 1] = mul(ways[n - 2], m - 1);
    ways[n] = mul(ways[n - 1], m);

    if (k > ways[n]) {
        cout << "-1\n";
        return 0;
    }
    rep(i, 1, n) {
        int need = (k + ways[n - i] - 1) / ways[n - i];
        a[i] = need;
        while (get_rank(i, a[i]) < need) ++a[i];
        k -= (need - 1) * ways[n - i];
        cout << a[i] << " \n"[i == n];
    }
    
    return 0;
}

详细

Test #1:

score: 100
Accepted
time: 2ms
memory: 3544kb

input:

1 1 1

output:

1

result:

ok 1 number(s): "1"

Test #2:

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

input:

2 2 2

output:

2 1

result:

ok 2 number(s): "2 1"

Test #3:

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

input:

3 3 3

output:

2 1 3

result:

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

Test #4:

score: 0
Accepted
time: 2ms
memory: 3496kb

input:

9 9 8244353

output:

2 4 1 2 6 8 1 2 7

result:

ok 9 numbers

Test #5:

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

input:

10 7 998244353

output:

-1

result:

ok 1 number(s): "-1"

Test #6:

score: 0
Accepted
time: 2ms
memory: 3504kb

input:

3 1000 994253860

output:

998 244 353

result:

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

Test #7:

score: 0
Accepted
time: 2ms
memory: 3452kb

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: 2ms
memory: 3372kb

input:

58 4 864691128455135233

output:

-1

result:

ok 1 number(s): "-1"

Test #9:

score: 0
Accepted
time: 70ms
memory: 15080kb

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: 61ms
memory: 15168kb

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

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: 2ms
memory: 3332kb

input:

2 2 1

output:

1 2

result:

ok 2 number(s): "1 2"

Test #14:

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

input:

3 2 4

output:

2 1 2

result:

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