QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#675509 | #6617. Encoded Strings I | abbcc_1# | WA | 0ms | 3612kb | C++20 | 1021b | 2024-10-25 18:43:31 | 2024-10-25 18:43:31 |
Judging History
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;
}
详细
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'