/ SeriousOJ /

Record Detail

Wrong Answer


  
# Status Time Cost Memory Cost
#1 Accepted 1ms 532.0 KiB
#2 Accepted 1ms 532.0 KiB
#3 Accepted 1ms 532.0 KiB
#4 Wrong Answer 1ms 532.0 KiB
#5 Accepted 35ms 3.23 MiB
#6 Accepted 35ms 3.18 MiB
#7 Accepted 35ms 3.223 MiB
#8 Accepted 61ms 3.406 MiB
#9 Accepted 35ms 3.281 MiB
#10 Accepted 36ms 3.207 MiB
#11 Accepted 1ms 532.0 KiB
#12 Accepted 1ms 532.0 KiB
#13 Accepted 1ms 532.0 KiB
#14 Accepted 1ms 356.0 KiB
#15 Accepted 1ms 532.0 KiB
#16 Accepted 1ms 512.0 KiB
#17 Accepted 1ms 324.0 KiB
#18 Accepted 1ms 336.0 KiB
#19 Accepted 1ms 324.0 KiB
#20 Wrong Answer 1ms 532.0 KiB

Code

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;
using std::mt19937_64;
using std::random_device;
using std::uniform_int_distribution;
#include <numeric>
#define ff              first
#define ss              second
#define int              long long
#define pb              push_back
#define mp              make_pair
#define pii             pair<int,int>
#define vi              vector<int>
#define mii             map<int,int>
#define pqb             priority_queue<int>
#define pqs             priority_queue<int,vi,greater<int> >
#define setbits(x)      __builtin_popcountll(x)
#define zrobits(x)      __builtin_ctzll(x)
#define mod             100000000000000000
#define inf             1e18
#define ps(x,y)         fixed<<setprecision(y)<<x
#define mk(arr,n,type)  type *arr=new type[n];
mt19937                 rng(chrono::steady_clock::now().time_since_epoch().count());
 
typedef tree<int, null_type, less<int>, rb_tree_tag,
             tree_order_statistics_node_update>
    pbds; 
 
void cpc()
{
#ifndef ONLINE_JUDGE
    freopen("shuffle.in", "r", stdin);
    freopen("shuffle.out", "w", stdout);
#endif
}
int dx[] = {-1, 0, 1, 0};
int dy[] = {0, 1, 0, -1};
int exp(int x, int n, int m) {
    if(x == 0 and n == 0) return 1;
    x %= m; 
    int res = 1;
    while (n > 0) {
        if (n % 2 == 1) { res = res * x % m; }
        x = x * x % m;
        n /= 2;
    }
    return res;
}
int gcd(int a,int b){
    if(a == 0) return b;
    return gcd(b%a,a);
}
bool check(int x,int y,int n,int m){
    if(x < 0 or y < 0 or x >= n or y >= m) return false;
    return true;
}
struct DSU {
    vector<int> parent, sz, ct;
    DSU(int n) {
        parent.resize(n+1);
        sz.assign(n+1, 1);
        ct.assign(n+1, 0);
        iota(parent.begin(), parent.end(), 0);
    }
    int find(int x) {
        return parent[x] == x ? x : parent[x] = find(parent[x]);
    }
    void unite(int a, int b) {
        a = find(a), b = find(b);
        if(a == b) return;
        if(sz[a] < sz[b]) swap(a, b);
        parent[b] = a;
        sz[a] += sz[b];
        ct[a] += ct[b];
    }
};
signed main()
{  
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    // cpc();
    int t=1;
    // cin >> t;
    while(t--){
     int n,k;
     cin >> n >> k;
     string s;
     cin >> s;
     multiset<char> s2;
     int i = n-1;
     int ct = 0;
     while(ct < k-1){
        s2.insert(s[i--]);
        ct++;
     }
     // for(auto &x:s2) cout<<x<<endl;
     vector<char> mi(n);
     while(i >= 0){
      s2.insert(s[i]);
      mi[i] = (*s2.begin());
      s2.erase(s2.find(s[i+k-1]));
      i--;
     }
     // for(int i = 0 ; i <= n-k; i++) cout<<mi[i]<<endl;
     i = 0;
     while(i <= n-k){
        if(s[i] > mi[i]){
            sort(s.begin()+i,s.begin()+i+k);
            i += k;
        }
        else i++;
     }
     cout<<s<<endl;

    }
    return 0;
}

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:27:16
Judged At
2025-09-02 17:27:16
Judged By
Score
18
Total Time
61ms
Peak Memory
3.406 MiB