QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#103665 | #6353. Kth Lex Min Min Min Subpalindromes | SEM_PRESSAO_pedroteosousa# | TL | 89ms | 19836kb | C++23 | 2.2kb | 2023-05-07 06:49:38 | 2023-05-07 06:49:41 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
long long INF = 1'000'000'000'000'000'010ll;
void solve1(int n, int m, long long k) {
if (k != 1) {
cout << -1 << endl;
return;
}
while (n--)
cout << "1 ";
cout << endl;
}
void solve2(int n, int m, long long k) {
if (n > 1000) while(true);
vector<string> r[] = {
{"1 ", "2 "},
{"1 2 ", "2 1 "},
{"1 1 2 ", "1 2 1 ", "1 2 2 ", "2 1 1 ", "2 1 2 ", "2 2 1 "},
{"1 1 2 1 ", "1 1 2 2 ", "1 2 1 1 ", "1 2 1 2 ", "1 2 2 1 ", "2 1 1 2 ", "2 1 2 1 ", "2 1 2 2 ", "2 2 1 1 ", "2 2 1 2 "},
{"1 1 2 1 2 ", "1 1 2 2 1 ", "1 2 1 1 2 ", "1 2 1 2 2 ", "1 2 2 1 1 ", "1 2 2 1 2 ", "2 1 1 2 1 ", "2 1 1 2 2 ", "2 1 2 1 1 ", "2 1 2 2 1 ", "2 2 1 1 2 ", "2 2 1 2 1 "},
{"1 1 2 1 2 2 ", "1 1 2 2 1 2 ", "1 2 1 1 2 2 ", "1 2 1 2 2 1 ", "1 2 2 1 1 2 ", "1 2 2 1 2 1 ", "2 1 1 2 1 2 ", "2 1 1 2 2 1 ", "2 1 2 1 1 2 ", "2 1 2 2 1 1 ", "2 2 1 1 2 1 ", "2 2 1 2 1 1 "}
};
int g = n >= 6 ? 5 : n - 1;
if (k > r[g].size()) {
cout << -1 << endl;
return;
}
string s = r[g][k - 1];
string resp = "";
for (int i = 0; i < 2 * n; i++) {
resp += s[i % s.size()];
}
cout << resp << endl;
}
long long mul(long long a, long long b, bool check = false) {
bool fodeu = a > numeric_limits<long long>::max() / b;
if (fodeu) {
if (check) assert(false);
return INF;
}
return a * b;
}
void solve3(int n, long long m, long long k) {
vector<long long> pot(n);
pot[0] = 1ll;
for (int i = 1; i < n; i++) {
pot[i] = mul(pot[i - 1], m - 2);
}
vector<long long> resp;
int l = m + 1, ll = m + 1;
long long mx = mul(m, mul(m - 1, pot[n - 2]));
if (mx < k) {
cout << -1 << endl;
return;
}
for (int i = 0; i < n; i++) {
long long x;
if (i == 0) {
x = mul(pot[n - 2], m - 1);
} else {
x = pot[n - i - 1];
}
long long r = (k - 1) / x;
k -= mul(r, x, true);
if (r >= min(l, ll)) r++;
if (r >= max(l, ll)) r++;
swap(l, ll);
l = r;
resp.push_back(r + 1ll);
}
for (auto r: resp)
cout << r << " ";
cout << endl;
}
int main() {
int n, m;
long long k;
cin >> n >> m >> k;
if (m == 1) solve1(n, m, k);
else if (m == 2) solve2(n, m, k);
else solve3(n, m, k);
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 2ms
memory: 3320kb
input:
1 1 1
output:
1
result:
ok 1 number(s): "1"
Test #2:
score: 0
Accepted
time: 2ms
memory: 3352kb
input:
2 2 2
output:
2 1
result:
ok 2 number(s): "2 1"
Test #3:
score: 0
Accepted
time: 2ms
memory: 3380kb
input:
3 3 3
output:
2 1 3
result:
ok 3 number(s): "2 1 3"
Test #4:
score: 0
Accepted
time: 0ms
memory: 3380kb
input:
9 9 8244353
output:
2 4 1 2 6 8 1 2 7
result:
ok 9 numbers
Test #5:
score: 0
Accepted
time: 1ms
memory: 3376kb
input:
10 7 998244353
output:
-1
result:
ok 1 number(s): "-1"
Test #6:
score: 0
Accepted
time: 0ms
memory: 3348kb
input:
3 1000 994253860
output:
998 244 353
result:
ok 3 number(s): "998 244 353"
Test #7:
score: 0
Accepted
time: 0ms
memory: 3360kb
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: 3432kb
input:
58 4 864691128455135233
output:
-1
result:
ok 1 number(s): "-1"
Test #9:
score: 0
Accepted
time: 83ms
memory: 19836kb
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: 89ms
memory: 19184kb
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: 2ms
memory: 3356kb
input:
1 1 2
output:
-1
result:
ok 1 number(s): "-1"
Test #12:
score: 0
Accepted
time: 0ms
memory: 3360kb
input:
1 2 2
output:
2
result:
ok 1 number(s): "2"
Test #13:
score: 0
Accepted
time: 2ms
memory: 3344kb
input:
2 2 1
output:
1 2
result:
ok 2 number(s): "1 2"
Test #14:
score: 0
Accepted
time: 2ms
memory: 3360kb
input:
3 2 4
output:
2 1 1
result:
ok 3 number(s): "2 1 1"
Test #15:
score: 0
Accepted
time: 0ms
memory: 3420kb
input:
3 2 7
output:
-1
result:
ok 1 number(s): "-1"
Test #16:
score: 0
Accepted
time: 2ms
memory: 3344kb
input:
4 2 10
output:
2 2 1 2
result:
ok 4 number(s): "2 2 1 2"
Test #17:
score: 0
Accepted
time: 2ms
memory: 3420kb
input:
4 2 3
output:
1 2 1 1
result:
ok 4 number(s): "1 2 1 1"
Test #18:
score: 0
Accepted
time: 2ms
memory: 3368kb
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: 3356kb
input:
5 2 13
output:
-1
result:
ok 1 number(s): "-1"
Test #20:
score: 0
Accepted
time: 0ms
memory: 3420kb
input:
6 2 5
output:
1 2 2 1 1 2
result:
ok 6 numbers
Test #21:
score: -100
Time Limit Exceeded
input:
1000000 2 3