QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#125333 | #6353. Kth Lex Min Min Min Subpalindromes | GenshinImpactsFault# | AC ✓ | 83ms | 16884kb | C++14 | 4.5kb | 2023-07-16 15:57:19 | 2023-07-16 15:57:31 |
Judging History
answer
#include <bits/stdc++.h>
#define fst first
#define snd second
#define pb push_back
using namespace std;
typedef long long ll;
const int N = 1000010;
const string ans2[] = {
"001011",
"001101",
"010011",
"010110",
"011001",
"011010",
"100101",
"100110",
"101001",
"101100",
"110010",
"110100"
};
namespace Sub {
vector<pair<int, string>> a;
string ss;
void dfs(int x, int n) {
if(x == n + 1) {
int cnt = n;
for(int i = 0; i < n; ++ i) {
for(int j = i - 1, k = i + 1; j >= 0 && k < n; -- j, ++ k) {
if(ss[j] == ss[k]) {
++ cnt;
}
else {
break;
}
}
}
for(int i = 0; i + 1 < n; ++ i) {
for(int j = i, k = i + 1; j >= 0 && k < n; -- j, ++ k) {
if(ss[j] == ss[k]) {
++ cnt;
}
else {
break;
}
}
}
a.push_back({cnt, ss});
return;
}
ss+='0';
dfs(x+1,n);
ss.pop_back();
ss+='1';
dfs(x+1,n);
ss.pop_back();
}
void MAIN(int nn, int mm, ll kk) {
a.clear(), ss.clear();
int n, m; ll k;
n = nn, m = mm, k = kk;
dfs(1, n);
sort(a.begin(),a.end());
for(; a.back().fst != a[0].fst;) a.pop_back();
if((int)a.size() < k) cout << "-1\n";
else {
for(auto v : a[k - 1].snd) cout << v - '0' + 1 << " ";
}
return ;
}
}
ll f[N];
bool check(int n, int m, ll k) {
--k;
k /= m;
if(n > 1) k /= (m - 1);
for(int i = 3; i <= n; i++) k /= (m - 2);
return k > 0;
}
int main() {
ios::sync_with_stdio(0); cin.tie(nullptr);
int n, m; ll k;
cin >> n >> m >> k;
if(n == 1) {
if(k > m) cout << "-1\n";
else cout << k << "\n";
return 0;
}
if(m == 2 && n <= 10) {
Sub::MAIN(n, m, k); return 0;
}
else if(m == 2) {
if(k > 12) cout << "-1\n";
else {
int id = k - 1;
for(int i = 1; i <= n; i++) cout << ans2[id][(i - 1) % 6] - '0' + 1 << " \n"[i == n];
}
return 0;
}
else if(m == 1) {
if(k > 1) cout << "-1\n";
else {
for(int i = 1; i <= n; i++) cout << "1 ";
}
return 0;
}
else if(m == 3) {
if(k > 6) cout << "-1\n";
else {
vector<int> ans(2);
if(k <= 2) ans[0] = 1;
else if(k <= 4) ans[0] = 2;
else ans[0] = 3;
if(k == 1 || k == 6) ans[1] = 2;
else if(k == 2 || k == 4) ans[1] = 3;
else ans[1] = 1;
for(int i = 2; i < n; i++) {
ans.pb(ans[(int)ans.size() - 1] ^ ans[(int)ans.size() - 2]);
}
for(auto v : ans) cout << v << " ";
}
return 0;
}
if(check(n, m, k)) {
cout << "-1\n"; return 0;
}
if(n == 1) {
cout << k << "\n"; return 0;
}
if(n == 2) {
cout << (k + m - 2) / (m - 1) << " ";
int val = (k + m - 2) / (m - 1), rem = k % (m - 1);
if(rem == 0) rem = m - 1;
if(rem >= val) ++rem;
cout << rem << "\n"; return 0;
}
fill(f + 1, f + n + 1, -1);
f[0] = 1;
int len;
for(int i = 1; i <= n; i++) {
if(f[i - 1] > (k + m - 3) / (m - 2)) {
len = i - 1; break;
}
f[i] = 1ll * f[i - 1] * (m - 2);
}
vector<int> ans;
for(int i = 1; i <= n; i++) {
// cout << ">>> " << i << " : " << k << "\n";
if(i == 1) {
if(f[n - 2] == -1) {
ans.pb(1); continue;
}
else if((k + m - 2) / (m - 1) < f[n - 2]) {
ans.pb(1);
continue;
}
ll siz = f[n - 2] * (m - 1);
ans.pb((k + siz - 1) / siz);
k %= siz; if(!k) k = siz;
continue;
}
int value;
if(f[n - i] == -1) value = 1;
else value = (k + f[n - i] - 1) / f[n - i];
vector<int> tmp;
for(int i = (int)ans.size() - 1; i >= 0 && (int)ans.size() - i <= 2; i--)
tmp.pb(ans[i]);
sort(tmp.begin(), tmp.end());
for(auto v : tmp)
if(value >= v) ++value;
ans.pb(value);
if(f[n - i] != -1) {
k %= f[n - i];
if(k == 0) k = f[n - i];
}
}
for(auto v : ans) cout << v << " ";
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 3412kb
input:
1 1 1
output:
1
result:
ok 1 number(s): "1"
Test #2:
score: 0
Accepted
time: 1ms
memory: 3460kb
input:
2 2 2
output:
2 1
result:
ok 2 number(s): "2 1"
Test #3:
score: 0
Accepted
time: 1ms
memory: 3452kb
input:
3 3 3
output:
2 1 3
result:
ok 3 number(s): "2 1 3"
Test #4:
score: 0
Accepted
time: 1ms
memory: 3460kb
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: 3412kb
input:
10 7 998244353
output:
-1
result:
ok 1 number(s): "-1"
Test #6:
score: 0
Accepted
time: 0ms
memory: 3420kb
input:
3 1000 994253860
output:
998 244 353
result:
ok 3 number(s): "998 244 353"
Test #7:
score: 0
Accepted
time: 1ms
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: 1ms
memory: 3436kb
input:
58 4 864691128455135233
output:
-1
result:
ok 1 number(s): "-1"
Test #9:
score: 0
Accepted
time: 81ms
memory: 16372kb
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: 83ms
memory: 15580kb
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: 3412kb
input:
1 1 2
output:
-1
result:
ok 1 number(s): "-1"
Test #12:
score: 0
Accepted
time: 1ms
memory: 3484kb
input:
1 2 2
output:
2
result:
ok 1 number(s): "2"
Test #13:
score: 0
Accepted
time: 0ms
memory: 3480kb
input:
2 2 1
output:
1 2
result:
ok 2 number(s): "1 2"
Test #14:
score: 0
Accepted
time: 0ms
memory: 3400kb
input:
3 2 4
output:
2 1 1
result:
ok 3 number(s): "2 1 1"
Test #15:
score: 0
Accepted
time: 0ms
memory: 3408kb
input:
3 2 7
output:
-1
result:
ok 1 number(s): "-1"
Test #16:
score: 0
Accepted
time: 1ms
memory: 3488kb
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: 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: 1ms
memory: 3484kb
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: 1ms
memory: 3460kb
input:
5 2 13
output:
-1
result:
ok 1 number(s): "-1"
Test #20:
score: 0
Accepted
time: 1ms
memory: 3468kb
input:
6 2 5
output:
1 2 2 1 1 2
result:
ok 6 numbers
Test #21:
score: 0
Accepted
time: 36ms
memory: 3468kb
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: 25ms
memory: 3480kb
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: 35ms
memory: 3408kb
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: 1ms
memory: 3476kb
input:
1000000 2 1000000000000000000
output:
-1
result:
ok 1 number(s): "-1"
Test #25:
score: 0
Accepted
time: 0ms
memory: 3520kb
input:
1 3 2
output:
2
result:
ok 1 number(s): "2"
Test #26:
score: 0
Accepted
time: 1ms
memory: 3420kb
input:
2 3 5
output:
3 1
result:
ok 2 number(s): "3 1"
Test #27:
score: 0
Accepted
time: 47ms
memory: 8796kb
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: 1ms
memory: 3420kb
input:
1000000 3 7
output:
-1
result:
ok 1 number(s): "-1"
Test #29:
score: 0
Accepted
time: 78ms
memory: 16336kb
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: 81ms
memory: 16884kb
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: 78ms
memory: 16576kb
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: 3460kb
input:
6 1000000 1000000000000000000
output:
1 2 4 9 15 8
result:
ok 6 numbers
Test #33:
score: 0
Accepted
time: 0ms
memory: 3480kb
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: 3404kb
input:
3 1000000 999997000002000000
output:
1000000 999999 999998
result:
ok 3 number(s): "1000000 999999 999998"
Test #35:
score: 0
Accepted
time: 1ms
memory: 3472kb
input:
3 1000000 999997000002000001
output:
-1
result:
ok 1 number(s): "-1"