/ SeriousOJ /

Record Detail

Wrong Answer


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

Code

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

typedef long long ll;
#define bug(a) cout << #a << " : " << a << endl;

signed main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);

    int t = 1; cin >> t;
    while (t--) {
        int n, m;cin >> n >> m;
        string s;cin >> s;

        string sorted_s = s;
        sort(sorted_s.begin(), sorted_s.end());
        vector<bool> swapped(n, false);
        for (int i = 0; i < n && m > 0; ++i) {
            if (s[i] == sorted_s[i]) continue;
            for (int j = i + 1; j < n; ++j) {
                if (s[j] == sorted_s[i] && !swapped[j]) {
                    swap(s[i], s[j]);
                    swapped[j] = true;
                    --m;
                    break;
                }
            }
        }
        cout << s << 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:24:55
Judged At
2024-12-13 12:24:55
Judged By
Score
5
Total Time
1ms
Peak Memory
540.0 KiB