QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#181208 | #6353. Kth Lex Min Min Min Subpalindromes | ucup-team859# | WA | 135ms | 19788kb | C++17 | 6.1kb | 2023-09-16 16:39:48 | 2023-09-16 16:39:48 |
Judging History
answer
#include <bits/stdc++.h>
#define lsb(x) (x & (-x))
using ull = unsigned long long;
using ll = long long;
using namespace std;
constexpr ll INF = 2e18;
inline ll mul(ll a, ll b) {
if (INF / b <= a) {
return INF;
}
return a * b;
}
inline ll logpow(ll a, ll b) {
ll result = 1;
while (b > 0) {
if (b & 1) result = mul(a, result);
b >>= 1;
a = mul(a, a);
}
return result;
}
int main() {
#ifdef HOME
ifstream cin("input.in");
ofstream cout("output.out");
#endif
ios::sync_with_stdio(false);
cin.tie(0), cout.tie(0);
int n, m;
ll k;
cin >> n >> m >> k;
if (m == 1) {
if (k > 1) {
cout << -1;
return 0;
}
for (int i = 1; i <= n; i++) {
cout << 1 << " ";
}
return 0;
}
if (m == 2) {
if (n <= 10) {
vector<string> strings;
int result = 1e9;
auto Get = [](string str) {
int n = (int)str.size();
int cnt = 0;
for (int i = 0; i < n; i++) {
for (int j = i; j < n; j++) {
int l = i, r = j;
while (l < r && str[l] == str[r]) {
l++, r--;
}
if (l >= r) {
cnt++;
}
}
}
return cnt;
};
for (int mask = 0; mask < (1 << n); mask++) {
string str;
for (int i = 0; i < n; i++) {
if (mask & (1 << i)) {
str += '2';
} else {
str += '1';
}
}
int cnt = Get(str);
if (result > cnt) {
strings.clear();
result = cnt;
}
if (result == cnt) {
strings.push_back(str);
}
}
sort(strings.begin(), strings.end());
strings.resize(unique(strings.begin(), strings.end()) - strings.begin());
if ((int)strings.size() < k) {
cout << -1;
} else {
for (auto itr : strings[k - 1]) {
cout << itr << " ";
}
}
return 0;
}
vector<string> strings;
int result = (int) 1e9;
auto Get = [](string str) {
int n = (int)str.size();
int cnt = n;
for (int i = 0; i < n; i++) {
if (i + 1 < n && str[i] == str[i + 1]) {
cnt++;
}
if (i + 2 < n && str[i] == str[i + 2]) {
cnt++;
}
if (i + 3 < n && str[i] == str[i + 3] && str[i + 1] == str[i + 2]) {
cnt++;
}
}
return cnt;
};
for (char first = '1'; first <= '2'; first++) {
char second = '1' - first + '2';
for (int x = 1; x <= 2; x++) {
for (int y = 1; y <= 2; y++) {
int pos = 0;
string str;
auto Add = [n](string& str, char ch, int len) {
while ((int)str.size() < n && len > 0) {
len--;
str += ch;
}
};
while ((int)str.size() < n) {
if (pos % 4 == 0) {
Add(str, first, x);
} else if (pos % 4 == 1) {
Add(str, second, y);
} else if (pos % 4 == 2) {
Add(str, first, 3 - x);
} else {
Add(str, second, 3 - y);
}
pos++;
}
int cnt = Get(str);
if (cnt < result) {
result = cnt;
strings.clear();
}
if (cnt == result) {
strings.push_back(str);
}
}
}
}
int size = (int)strings.size();
for (int i = 0; i < size; i++) {
auto s = strings[i];
reverse(s.begin(), s.end());
strings.push_back(s);
}
sort(strings.begin(), strings.end());
strings.resize(unique(strings.begin(), strings.end()) - strings.begin());
// cerr << strings.size() << "\n";
// for (auto itr : strings) {
// cerr << itr << " " << Get(itr) << "\n";
// }
if ((int)strings.size() < k) {
cout << -1;
} else {
for (auto itr : strings[k - 1]) {
cout << itr << " ";
}
}
return 0;
}
ll total = mul(m, mul(m - 1, logpow(m - 2, n - 2)));
if (total < k) {
cout << -1;
return 0;
}
vector<ll> v(n);
ll coef0 = mul(m - 1, logpow(m - 2, n - 2));
ll v0 = (k - 1) / coef0 + 1;
k -= (v0 - 1) * coef0;
v[0] = v0;
ll coef1 = logpow(m - 2, n - 2);
ll v1 = (k - 1) / coef1 + 1;
k -= (v1 - 1) * coef1;
v[1] = (v1 < v0 ? v1 : v1 + 1);
for (int i = 2; i < n; i++) {
ll coef = logpow(m - 2, n - i - 1);
ll vi = (k - 1) / coef + 1;
k -= (vi - 1) * coef;
if (vi >= min(v[i - 1], v[i - 2])) {
vi++;
}
if (vi >= max(v[i - 1], v[i - 2])) {
vi++;
}
v[i] = vi;
}
for (auto itr : v) {
cout << itr << " ";
}
return 0;
}
详细
Test #1:
score: 100
Accepted
time: 1ms
memory: 3448kb
input:
1 1 1
output:
1
result:
ok 1 number(s): "1"
Test #2:
score: 0
Accepted
time: 1ms
memory: 3500kb
input:
2 2 2
output:
2 1
result:
ok 2 number(s): "2 1"
Test #3:
score: 0
Accepted
time: 1ms
memory: 3456kb
input:
3 3 3
output:
2 1 3
result:
ok 3 number(s): "2 1 3"
Test #4:
score: 0
Accepted
time: 1ms
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: 1ms
memory: 3444kb
input:
10 7 998244353
output:
-1
result:
ok 1 number(s): "-1"
Test #6:
score: 0
Accepted
time: 1ms
memory: 3516kb
input:
3 1000 994253860
output:
998 244 353
result:
ok 3 number(s): "998 244 353"
Test #7:
score: 0
Accepted
time: 0ms
memory: 3400kb
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: 3460kb
input:
58 4 864691128455135233
output:
-1
result:
ok 1 number(s): "-1"
Test #9:
score: 0
Accepted
time: 134ms
memory: 10868kb
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: 135ms
memory: 11016kb
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: 3440kb
input:
1 1 2
output:
-1
result:
ok 1 number(s): "-1"
Test #12:
score: 0
Accepted
time: 0ms
memory: 3520kb
input:
1 2 2
output:
2
result:
ok 1 number(s): "2"
Test #13:
score: 0
Accepted
time: 1ms
memory: 3516kb
input:
2 2 1
output:
1 2
result:
ok 2 number(s): "1 2"
Test #14:
score: 0
Accepted
time: 1ms
memory: 3448kb
input:
3 2 4
output:
2 1 1
result:
ok 3 number(s): "2 1 1"
Test #15:
score: 0
Accepted
time: 0ms
memory: 3468kb
input:
3 2 7
output:
-1
result:
ok 1 number(s): "-1"
Test #16:
score: 0
Accepted
time: 1ms
memory: 3504kb
input:
4 2 10
output:
2 2 1 2
result:
ok 4 number(s): "2 2 1 2"
Test #17:
score: 0
Accepted
time: 1ms
memory: 3524kb
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: 3524kb
input:
5 2 13
output:
-1
result:
ok 1 number(s): "-1"
Test #20:
score: 0
Accepted
time: 0ms
memory: 3504kb
input:
6 2 5
output:
1 2 2 1 1 2
result:
ok 6 numbers
Test #21:
score: 0
Accepted
time: 34ms
memory: 19756kb
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: -100
Wrong Answer
time: 57ms
memory: 19788kb
input:
1000000 2 5
output:
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 1 2 1 ...
result:
wrong answer 5th numbers differ - expected: '1', found: '2'