/ SeriousOJ /

Record Detail

Wrong Answer


  
# Status Time Cost Memory Cost
#1 Accepted 2ms 332.0 KiB
#2 Wrong Answer 2ms 328.0 KiB
#3 Wrong Answer 2ms 372.0 KiB

Code

#include<bits/stdc++.h>
using namespace std;
#define ll long long

struct st{
    char ch;
    int in;
};

bool cmp(st x, st y){
    if(x.ch==y.ch) return x.in<y.in;
    return x.ch<y.ch;
}

int main()
{
    ll t;
    cin>>t;
    while(t--){
        int n,m;
        cin>>n>>m;

        string str;
        cin>>str;

        multimap<char,int >mp;

        for(int i=0;i<n;i++){
            mp.insert({str[i],i});
        }

        for(int i=0;i<n;i++){
            auto val=mp.find(str[i]);
            pair<char,int> v=*mp.begin();

            if(str[i]!=v.first && m>0){
                int in=v.second;
                mp.erase(val);
                mp.insert({str[i],in});
                swap(str[i],str[in]);
                m--;
            }
            mp.erase(mp.begin());
        }

        cout<<str<<endl;

        /*st s[n];
        for(int i=0;i<n;i++){
            s[i].ch=str[i];
            s[i].in=i;
        }

        sort(s,s+n,cmp);

        for(int i=0;i<n;i++){
            if(str[i]!=s[i].ch && m>0){
                swap(str[i],str[s[i].in]);
                swap()
                m--;
            }
        }

        cout<<str<<endl;*/
    }
}

Information

Submit By
Type
Submission
Problem
P1058 Lexicographically Smallest String
Contest
Sylhet ICPC 2024 Collaborative Challenge: Episode 2
Language
C++17 (G++ 13.2.0)
Submit At
2024-10-30 11:20:46
Judged At
2024-11-11 02:34:55
Judged By
Score
5
Total Time
2ms
Peak Memory
372.0 KiB