/ SeriousOJ /

Record Detail

Wrong Answer


  
# Status Time Cost Memory Cost
#1 Accepted 1ms 324.0 KiB
#2 Accepted 1ms 532.0 KiB
#3 Accepted 1ms 532.0 KiB
#4 Wrong Answer 1ms 532.0 KiB
#5 Accepted 59ms 5.324 MiB
#6 Accepted 55ms 5.406 MiB
#7 Accepted 54ms 5.406 MiB
#8 Accepted 56ms 5.406 MiB
#9 Accepted 54ms 5.375 MiB
#10 Accepted 53ms 5.406 MiB
#11 Accepted 1ms 532.0 KiB
#12 Accepted 1ms 536.0 KiB
#13 Accepted 4ms 532.0 KiB
#14 Accepted 4ms 532.0 KiB
#15 Accepted 4ms 324.0 KiB
#16 Accepted 4ms 532.0 KiB
#17 Accepted 4ms 324.0 KiB
#18 Accepted 4ms 516.0 KiB
#19 Accepted 4ms 532.0 KiB
#20 Wrong Answer 4ms 532.0 KiB

Code

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

signed main() {
    ios_base::sync_with_stdio(0); cin.tie(0);
    ll n, k; cin >> n >> k;
    string s; cin >> s;

    ll indx[n];
    for (ll i = 0; i < n; i++) indx[i] = -1;

    ll j = n-1;
    set<pair<char, ll>> st;
    for (ll i = n-1; i >= 0; i--) {
        if (st.size() >= k) {
            st.erase({s[j], j});
            j--;
        }
        st.insert({s[i], i});

        if (st.size() == k) {
            auto it = *st.begin();
            if (it.first < s[i]) indx[i] = it.second;
        }   
    }

    for (ll i = 0; i < n; ) {
        if (indx[i] == -1) {
            cout << s[i];
            i++;
            continue;
        }
        string temp = s.substr(i, k);
        sort(temp.begin(), temp.end());
        cout << temp;
        i += k;
    }
}

Information

Submit By
Type
Submission
Problem
P1230 Lexicographically Smallest Rearrangement
Contest
LUCC Presents Intra LU Junior Programming Contest - Replay
Language
C++17 (G++ 13.2.0)
Submit At
2025-09-02 17:39:43
Judged At
2025-09-02 17:39:43
Judged By
Score
18
Total Time
59ms
Peak Memory
5.406 MiB