QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#249929#4707. Do Geese See God?JeffreyWA 8ms51460kbC++142.2kb2023-11-12 18:11:082023-11-12 18:11:08

Judging History

你现在查看的是最新测评结果

  • [2023-11-12 18:11:08]
  • 评测
  • 测评结果:WA
  • 用时:8ms
  • 内存:51460kb
  • [2023-11-12 18:11:08]
  • 提交

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--;
            }
        }
    }
    if (d[1][n] % 2) for (int i = d[1][n] / 2 - 1; i >= 0; i--) z += z[i];
    else for (int i = d[1][n] / 2; i >= 0; i--) z += z[i];
    cout << z << '\n';
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 5ms
memory: 51460kb

input:

crc
1

output:

crc

result:

ok single line: 'crc'

Test #2:

score: 0
Accepted
time: 8ms
memory: 51372kb

input:

icpc
1

output:

icpci

result:

ok single line: 'icpci'

Test #3:

score: -100
Wrong Answer
time: 4ms
memory: 51396kb

input:

hello
1

output:

heol

result:

wrong answer 1st lines differ - expected: 'heolloeh', found: 'heol'