/ SeriousOJ /

Record Detail

Wrong Answer


  
# Status Time Cost Memory Cost
#1 Accepted 1ms 532.0 KiB
#2 Wrong Answer 1ms 536.0 KiB
#3 Wrong Answer 1ms 324.0 KiB

Code

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

void solve()
{
    int n, m; cin >> n >> m;

    string s; cin >> s;
    int last = 0;
    for(char i = 'a'; i <= 'z'; i++){
    	if(m == 0){
    		break;
    	}
    	for(int f = last; f <= n; f++){
    		if(s[f] == i){
    			last++;
    		}
    		else{
    			break;
    		}
    	}
    	int l = n - 1, f = last;
    	while(f < l){
    		if(m == 0){
    			break;
    		}
    		if(s[l] == i && s[f] > i){
    			swap(s[l], s[f]);
    			f++, l--;
    			m--;
    		}
    		else if(s[l] != i){
    			l--;
    		}
    		else if(s[f] == i){
    			f++;
    		}
    		else if(s[l] == i && s[f] <= i){
    			f++;
    		}

    		if(m == 0){
    			break;
    		}
    	}
    	last = f;
    	if(m == 0){
    		break;
    	}
    }

    cout << s << endl;

}


int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);

    int t = 1, tc = 0;
    cin >> t;

    while(t--){
    	//cout << "Case " << ++tc << ": ";
    	solve();
    } 
}


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 09:34:55
Judged At
2024-11-11 02:35:18
Judged By
Score
5
Total Time
1ms
Peak Memory
536.0 KiB