QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#771186#6617. Encoded Strings ITauLee01WA 0ms3656kbC++231.2kb2024-11-22 10:33:022024-11-22 10:33:02

Judging History

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

  • [2024-11-22 10:33:02]
  • 评测
  • 测评结果:WA
  • 用时:0ms
  • 内存:3656kb
  • [2024-11-22 10:33:02]
  • 提交

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'