QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#175576#5680. You You See What?Fr1nGeLoveWA 1ms3860kbC++203.0kb2023-09-10 19:54:392023-09-10 19:54:39

Judging History

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

  • [2023-09-10 19:54:39]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:3860kb
  • [2023-09-10 19:54:39]
  • 提交

answer

#include <bits/stdc++.h>

using i64 = long long;

int main() {
    std::ios::sync_with_stdio(false);
    std::cin.tie(nullptr);

    std::string s;
    std::cin >> s;

    std::map<std::string, int> f;
    std::map<int, std::string> g;
    int idx = 0;
    std::vector<int> a;
    for (int i = 0; i < s.size(); i++) {
        int j = i;
        while (j < s.size() && s[j] != '!') {
            j++;
        }
        std::string str = s.substr(i, j - i);
        std::string ss = "";
        for (auto x : str) {
            ss += std::tolower(x);
        }
        if (!f.count(ss)) {
            f[ss] = idx++;
            g[f[ss]] = str;
        }
        a.push_back(f[ss]);
        i = j;
    }

    const int n = a.size();
    int t = a.back();
    a.pop_back();
    // for (auto x : a) {
    //     std::cerr << x << " ";
    // }
    // std::cerr << "\n";
    int mx = 1;
    while (1) {
        // for (auto x : a) {
        //     std::cerr << x << " ";
        // }
        // std::cerr << "\n";
        std::vector<int> u;
        std::vector<int> v;
        for (int i = 0; i < a.size(); i++) {
            int cnt = 0;
            for (int l = i - 1, r = i + 1; l >= 0 && r < a.size(); l--, r++) {
                if (a[l] == a[r]) {
                    cnt++;
                }
            }
            u.push_back(cnt);
            cnt = 0;
            if (i + 1 < a.size() && a[i] == a[i + 1]) {
                cnt++;
                for (int l = i - 1, r = i + 2; l >= 0 && r < a.size(); l--, r++) {
                    if (a[l] == a[r]) {
                        cnt++;
                    }
                }
            }
            v.push_back(cnt);
        }
        // std::cerr << "check : \n";
        // for (auto x : u) {
        //     std::cerr << x << " ";
        // }
        // std::cerr << "\n";
        // for (auto x : v) {
        //     std::cerr << x << " ";
        // }
        // std::cerr << "\n";

        int mx1 = *std::max_element(u.begin(), u.end());
        int mx2 = *std::max_element(v.begin(), v.end());
        // std::cerr << mx1 << " " << mx2 << "\n";
        if (mx1 == 0 && mx2 == 0) {
            break;
        }
        int val1 = 2 * mx1 + 1, val2 = (mx2 == 0 ? 0 : 2 * mx2);
        if (val1 > val2) {
            int p = 0;
            for (int i = 0; i < u.size(); i++) {
                if (mx1 == u[i]) {
                    p = i;
                    break;
                }
            }
            // std::cerr << p << "\n";
            a.erase(a.begin() + p - mx1 + 1, a.begin() + p + mx1 + 1);
        } else {
            int p = 0;
            for (int i = 0; i < v.size(); i++) {
                if (mx2 == v[i]) {
                    p = i;
                    break;
                }
            }
            a.erase(a.begin() + p - mx2 + 2, a.begin() + p + mx2 + 1);
        }
    }

    for (int i = 0; i < a.size(); i++) {
        std::cout << g[a[i]] << "!";
    }
    std::cout << g[t];
    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 1ms
memory: 3672kb

input:

texasam!rice!baylor!csdept!baylor!rice!dev!bresearch!bpoucher

output:

texasam!rice!dev!bresearch!bpoucher

result:

ok single line: 'texasam!rice!dev!bresearch!bpoucher'

Test #2:

score: 0
Accepted
time: 0ms
memory: 3792kb

input:

texasam!Rice!baYlor!csdept!BayloR!dev!Rice!bresearch!bpoucher

output:

texasam!Rice!baYlor!dev!Rice!bresearch!bpoucher

result:

ok single line: 'texasam!Rice!baYlor!dev!Rice!bresearch!bpoucher'

Test #3:

score: 0
Accepted
time: 1ms
memory: 3860kb

input:

bresearch!bpoucher

output:

bresearch!bpoucher

result:

ok single line: 'bresearch!bpoucher'

Test #4:

score: -100
Wrong Answer
time: 1ms
memory: 3576kb

input:

a!b!c!d!e!f!g!h!i!j!k!l!m!n!o!p!q!r!s!t!u!v!w!x!y!z!a!b!c!d!e!f!g!h!i!j!k!l!m!n!o!p!q!r!s!t!u!v!w!x!y!z!a!b!c!d!e!f!g!h!i!j!k!l!m!n!o!p!q!r!s!t!u!v!w!x!y!z!a!b!c!d!e!f!g!h!i!j!k!l!m!n!o!p!q!r!s!t!u!v!w!x!y!z!a!b!c!d!e!f!g!h!i!j!k!l!m!n!o!p!q!r!s!t!u!v!w!x

output:

a!b!c!d!e!f!g!h!i!j!k!l!m!n!o!p!q!r!s!t!u!v!w!x

result:

wrong answer 1st lines differ - expected: 'a!b!c!d!e!f!g!h!i!j!k!l!m!n!o!...i!j!k!l!m!n!o!p!q!r!s!t!u!v!w!x', found: 'a!b!c!d!e!f!g!h!i!j!k!l!m!n!o!p!q!r!s!t!u!v!w!x'