QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#240792 | #6617. Encoded Strings I | He2717970784 | WA | 1ms | 3448kb | C++17 | 679b | 2023-11-05 19:07:45 | 2023-11-05 19:07:46 |
Judging History
answer
#include<iostream>
#include<vector>
#include<string>
using namespace std;
string solve(string s) {
int n = s.length();
vector<int>pos(26, -1), num(n, 0);
for (int i = 0; i < n; i++) {
pos[s[i] - 'a'] = i;
}
for (int i = 0; i < n; i++) {
for (int j = 0; j < 26; j++) {
if (pos[j] > i) {
num[i]++;
}
}
}
string ans;
for (int i = 0; i < n; i++) {
ans += 'a' + num[pos[s[i] - 'a']];
}
return ans;
}
int main() {
int n = 0;
cin >> n;
string s,ans;
cin >> s;
for (int i = 0; i < (int)s.length(); i++) {
string res = solve(s.substr(i));
if (res > ans) {
ans = res;
}
}
cout << ans << endl;
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 1ms
memory: 3356kb
input:
4 aacc
output:
bbaa
result:
ok single line: 'bbaa'
Test #2:
score: 0
Accepted
time: 0ms
memory: 3448kb
input:
3 aca
output:
ba
result:
ok single line: 'ba'
Test #3:
score: 0
Accepted
time: 0ms
memory: 3368kb
input:
1 t
output:
a
result:
ok single line: 'a'
Test #4:
score: -100
Wrong Answer
time: 0ms
memory: 3396kb
input:
12 bcabcabcbcbb
output:
cabcababaa
result:
wrong answer 1st lines differ - expected: 'cbacba', found: 'cabcababaa'