/ SeriousOJ /

Record Detail

Wrong Answer


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

Code

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

string f(string &s, int n, long long m) {
    for (int i = 0; i < n && m > 0; i++) {
        char minChar = s[i];
        int minIndex = i;

        for (int j = i + 1; j < n; j++) {
            if (s[j] < minChar) {
                minChar = s[j];
                minIndex = j;
            }
        }

        if (minIndex != i && m > 0) {
            swap(s[i], s[minIndex]);
            m--;
        }
    }
    return s;
}

int main() {
    int T;
    cin >> T;

    while (T--) {
        int n;
        long long m;
        string s;

        cin >> n >> m >> s;
        cout << f(s, n, m) << endl;
    }

    return 0;
}

Information

Submit By
Type
Submission
Problem
P1058 Lexicographically Smallest String
Language
C++17 (G++ 13.2.0)
Submit At
2024-12-13 12:37:52
Judged At
2024-12-13 12:37:52
Judged By
Score
5
Total Time
1ms
Peak Memory
540.0 KiB