QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#216103#6617. Encoded Strings IzhuibaoWA 0ms3628kbC++201.5kb2023-10-15 15:46:452023-10-15 15:46:46

Judging History

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

  • [2023-10-15 15:46:46]
  • 评测
  • 测评结果:WA
  • 用时:0ms
  • 内存:3628kb
  • [2023-10-15 15:46:45]
  • 提交

answer

#define IO ios::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#include<bits/stdc++.h>
using namespace std;
typedef long long ll; typedef unsigned long long ull; typedef pair<ll, ll>pi; typedef complex<double>cx;
#define int ll
#define X first
#define Y second
#define fer(i,a,n) for(int i=a;i<=n;i++)
#define ref(i,n,a) for(int i=n;i>=a;i--)
#define endl '\n'
#define mem(a,x) memset(a,x,sizeof a)
#define ac IO;int t;cin>>t;while(t--)solve()
#define AC signed main(){IO;solve();}
#define NO {cout<<"NO"<<endl;return;}
#define YES {cout<<"YES"<<endl;return;}
#define re(a) {cout<<a<<endl;return;}
#define all(v) v.begin(),v.end()
//ofstream fout("1.out", ios::out);
//ifstream fin("1.in", ios::in);
//#define cout fout
//#define cin fin
//--------------------瑞神神中神--------------------

const int N=1010,M=30;
int rk[M];
int n,cnt;
string s;

bool cmp(string &s1,string &s2)
{
    for(int i=0;i<min(s1.size(),s2.size());i++)
    {
        if(s1[i]>s2[i])return 1;
        else if(s1[i]<s2[i])return 0;
    }
    return s1.size()>s2.size();
}

void solve()
{
    cin>>n>>s;
    s=" "+s;
    memset(rk,-1,sizeof rk);
    for(int i=n;i>=1;i--)
    {
        if(rk[s[i]-'a']==-1)rk[s[i]-'a']=cnt++;
    }
    string tmp;
    vector<string>vec;
    for(int i=n;i>=1;i--)
    {
        char ch=rk[s[i]-'a']+'a';
        tmp.push_back(ch);
        string t=tmp;
        reverse(t.begin(),t.end());
        vec.emplace_back(t);
    }
    string ans=*min_element(vec.begin(),vec.end(),cmp);
    cout<<ans<<'\n';
}

AC

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 0ms
memory: 3620kb

input:

4
aacc

output:

bbaa

result:

ok single line: 'bbaa'

Test #2:

score: 0
Accepted
time: 0ms
memory: 3568kb

input:

3
aca

output:

ba

result:

ok single line: 'ba'

Test #3:

score: 0
Accepted
time: 0ms
memory: 3528kb

input:

1
t

output:

a

result:

ok single line: 'a'

Test #4:

score: -100
Wrong Answer
time: 0ms
memory: 3628kb

input:

12
bcabcabcbcbb

output:

cabcababaa

result:

wrong answer 1st lines differ - expected: 'cbacba', found: 'cabcababaa'