QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#771186 | #6617. Encoded Strings I | TauLee01 | WA | 0ms | 3656kb | C++23 | 1.2kb | 2024-11-22 10:33:02 | 2024-11-22 10:33:02 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define endl '\n'
#define inf 0x3f3f3f3f3f3f3f3f
const int maxn = 1e5 + 10;
const int mod = 1e9 + 7;
void solve()
{
int n;
cin >> n;
string s;
cin >> s;
// int n = s.size();
s = ' ' + s;
int cnt = 1;
int pos = n;
map<int, int> ma;
int maxx = 0;
string ss = "";
string tt = "";
for (int i = n; i >= 1; i--)
{
if (!ma[s[i] - 'a'])
ma[s[i] - 'a'] = cnt++;
if (i == n)
{
ss = char(ma[s[i] - 'a'] + 'a' - 1) + ss;
tt = char(ma[s[i] - 'a'] + 'a' - 1) + tt;
pos = i;
}
else
{
tt = char(ma[s[i] - 'a'] + 'a' - 1) + tt;
// cout << ss << " " << tt << endl;
if (tt > ss)
{
ss = tt;
pos = i;
}
}
}
// cout << pos << endl;
// return;
for (int i = pos; i <= n; i++)
{
cout << char(ma[s[i] - 'a'] + 'a' - 1);
}
}
signed main()
{
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int t = 1;
// cin >> t;
while (t--)
solve();
return 0;
}
詳細信息
Test #1:
score: 100
Accepted
time: 0ms
memory: 3656kb
input:
4 aacc
output:
bbaa
result:
ok single line: 'bbaa'
Test #2:
score: 0
Accepted
time: 0ms
memory: 3616kb
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: 3612kb
input:
12 bcabcabcbcbb
output:
cabcababaa
result:
wrong answer 1st lines differ - expected: 'cbacba', found: 'cabcababaa'