QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#675509#6617. Encoded Strings Iabbcc_1#WA 0ms3612kbC++201021b2024-10-25 18:43:312024-10-25 18:43:31

Judging History

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

  • [2024-10-25 18:43:31]
  • 评测
  • 测评结果:WA
  • 用时:0ms
  • 内存:3612kb
  • [2024-10-25 18:43:31]
  • 提交

answer

#include <bits/stdc++.h>

using namespace std;

using i64 = long long;

string solve(string s) {
    string ans = "";
    vector<int> lst(26, -1), cnt(26, 0);
    for (int i = s.size() - 1; i >= 0; i -= 1) {
        if (lst[s[i] - 'a'] == -1) {
            lst[s[i] - 'a'] = i;
        }
    }
    for (int i = 0; i < 26; i += 1) {
        if (lst[i] == -1) continue;
        int vis[26]{};
        for (int j = lst[i] + 1; j < s.size(); j += 1) {
            vis[s[i] - 'a'] = 1;
        }
        for (int j = 0; j < 26; j += 1) {
            cnt[i] += vis[j];
        }
    }
    for (auto x : s) {
        ans.push_back(cnt[x - 'a'] + 'a');
    }
    return ans;
}

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

    int n;
    cin >> n;

    string s;
    cin >> s;

    string res = "";

    for (int i = 1; i <= n; i += 1) {
        string t = s.substr(0, i);
        res = max(res, solve(t));
    }
    cout << res << "\n";

    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 0ms
memory: 3524kb

input:

4
aacc

output:

bbaa

result:

ok single line: 'bbaa'

Test #2:

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

input:

3
aca

output:

ba

result:

ok single line: 'ba'

Test #3:

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

input:

1
t

output:

a

result:

ok single line: 'a'

Test #4:

score: -100
Wrong Answer
time: 0ms
memory: 3536kb

input:

12
bcabcabcbcbb

output:

bbabba

result:

wrong answer 1st lines differ - expected: 'cbacba', found: 'bbabba'