QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#249932 | #4707. Do Geese See God? | Jeffrey | WA | 8ms | 51556kb | C++14 | 2.2kb | 2023-11-12 18:12:12 | 2023-11-12 18:12:13 |
Judging History
answer
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <cmath>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
const int mod = 1000000007;
int main() {
string s;
int d[2023][2023] = {};
ll k, e[2023][2023] = {};
cin >> s >> k;
int n = (int)s.length();
s = '!' + s;
for (int i = 1; i < n; i++) e[i + 1][i] = 1;
for (int j = 1; j <= n; j++) for (int i = j; i; i--) {
if (i == j) d[i][j] = 1, e[i][j] = 1;
else if (s[i] == s[j]) d[i][j] = d[i + 1][j - 1] + 2, e[i][j] = e[i + 1][j - 1];
else if (d[i + 1][j] < d[i][j - 1]) d[i][j] = d[i + 1][j] + 2, e[i][j] = e[i + 1][j];
else if (d[i + 1][j] > d[i][j - 1]) d[i][j] = d[i][j - 1] + 2, e[i][j] = e[i][j - 1];
else d[i][j] = d[i + 1][j] + 2, e[i][j] = min(1ll * mod * mod, e[i + 1][j] + e[i][j - 1]);
}
//for (int i = 1; i <= n; i++) for (int j = 1; j <= n; j++) cout << d[i][j] << " \n"[j == n];
//for (int i = 1; i <= n; i++) for (int j = 1; j <= n; j++) cout << e[i][j] << " \n"[j == n];
if (e[1][n] < k) {
cout << "NONE\n";
return 0;
}
k--;
int l = 1, r = n;
string z;
while (l <= r) {
//cout << l << ' ' << r << ' ' << d[l][r] << ' ' << e[l][r] << ' ' << k << '\n';
if (s[l] == s[r]) {
z += s[l];
l++;
r--;
} else if (d[l + 1][r] < d[l][r - 1]) {
z += s[l];
l++;
} else if (d[l + 1][r] > d[l][r - 1]) {
z += s[r];
r--;
} else if (s[l] > s[r]) {
if (k < e[l][r - 1]) {
z += s[r];
r--;
} else {
k -= e[l][r - 1];
z += s[l];
l++;
}
} else {
if (k < e[l + 1][r]) {
z += s[l];
l++;
} else {
k -= e[l + 1][r];
z += s[r];
r--;
}
}
}
cout << z;
if (d[1][n] % 2) for (int i = d[1][n] / 2 - 1; i >= 0; i--) cout << z[i];
else for (int i = d[1][n] / 2; i >= 0; i--) cout << z[i];
cout << '\n';
}
详细
Test #1:
score: 100
Accepted
time: 4ms
memory: 51444kb
input:
crc 1
output:
crc
result:
ok single line: 'crc'
Test #2:
score: 0
Accepted
time: 8ms
memory: 51556kb
input:
icpc 1
output:
icpci
result:
ok single line: 'icpci'
Test #3:
score: -100
Wrong Answer
time: 4ms
memory: 51532kb
input:
hello 1
output:
heol
result:
wrong answer 1st lines differ - expected: 'heolloeh', found: 'heol'