QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#125325 | #6353. Kth Lex Min Min Min Subpalindromes | GenshinImpactsFault# | WA | 2ms | 3484kb | C++14 | 4.3kb | 2023-07-16 15:47:02 | 2023-07-16 15:47:06 |
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 /= 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(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++) {
if(i == 1) {
if(f[n - 2] == -1) ans.pb(1);
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 = 2;
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;
}
详细
Test #1:
score: 100
Accepted
time: 2ms
memory: 3412kb
input:
1 1 1
output:
1
result:
ok 1 number(s): "1"
Test #2:
score: 0
Accepted
time: 0ms
memory: 3440kb
input:
2 2 2
output:
2 1
result:
ok 2 number(s): "2 1"
Test #3:
score: 0
Accepted
time: 0ms
memory: 3476kb
input:
3 3 3
output:
2 1 3
result:
ok 3 number(s): "2 1 3"
Test #4:
score: 0
Accepted
time: 1ms
memory: 3476kb
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: 3420kb
input:
10 7 998244353
output:
-1
result:
ok 1 number(s): "-1"
Test #6:
score: 0
Accepted
time: 1ms
memory: 3484kb
input:
3 1000 994253860
output:
998 244 353
result:
ok 3 number(s): "998 244 353"
Test #7:
score: -100
Wrong Answer
time: 1ms
memory: 3472kb
input:
58 4 864691128455135232
output:
-1
result:
wrong answer 1st numbers differ - expected: '4', found: '-1'