QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#240792#6617. Encoded Strings IHe2717970784WA 1ms3448kbC++17679b2023-11-05 19:07:452023-11-05 19:07:46

Judging History

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

  • [2023-11-05 19:07:46]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:3448kb
  • [2023-11-05 19:07:45]
  • 提交

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;
}

详细

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'