Submission #28861823


Source Code Expand

#include <assert.h>

#include <algorithm>
#include <bitset>
#include <cctype>
#include <cmath>
#include <complex>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <tuple>
#include <unordered_map>
#include <utility>
#include <vector>
#define _overload3(_1, _2, _3, name, ...) name
#define _rep(i, n) repi(i, 0, n)
#define repi(i, a, b) for (ll i = a; i < b; ++i)
#define rep(...) _overload3(__VA_ARGS__, repi, _rep, )(__VA_ARGS__)
#define _rrep(i, a) rrepi(i, a, 0)
#define rrepi(i, a, b) for (ll i = a - 1; i >= b; --i)
#define rrep(...) _overload3(__VA_ARGS__, rrepi, _rrep, )(__VA_ARGS__)
#define all(x) (x).begin(), (x).end()
#define PRINT(V) cout << V << "\n"
#define SORT(V) sort((V).begin(), (V).end())
#define RSORT(V) sort((V).rbegin(), (V).rend())
using namespace std;
using ll = long long;
using ull = unsigned long long;
template <class T>
bool chmax(T& a, const T& b) {
    if (a < b) {
        a = b;
        return 1;
    }
    return 0;
}
template <class T>
bool chmin(T& a, const T& b) {
    if (b < a) {
        a = b;
        return 1;
    }
    return 0;
}
inline void Yes(bool condition) {
    if (condition)
        PRINT("Yes");
    else
        PRINT("No");
}
template <class itr>
void cins(itr first, itr last) {
    for (auto i = first; i != last; i++) {
        cin >> (*i);
    }
}
template <class itr>
void array_output(itr start, itr goal) {
    string ans = "", k = " ";
    for (auto i = start; i != goal; i++) ans += to_string(*i) + k;
    if (!ans.empty()) ans.pop_back();
    PRINT(ans);
}
ll gcd(ll a, ll b) { return a ? gcd(b % a, a) : b; }

const ll INF = 1e18;
const ll MOD = 1000000007;
const ll MOD2 = 998244353;
const ll MOD3 = 1e6;
const ll EPS = 1e-10;
int sgn(const double a) { return (a < -EPS ? -1 : (a > EPS ? +1 : 0)); }
typedef pair<int, int> pi;
typedef pair<ll, ll> P;
typedef tuple<ll, ll, ll> tri;
typedef pair<double, double> point;
typedef complex<double> Point;
const ll MAX = 100005;
constexpr ll nx[4] = {-1, 0, 1, 0};
constexpr ll ny[4] = {0, 1, 0, -1};



int main() {
    ll n;
    cin >> n;
    string s;
    cin >> s;
    vector<ll> cnt(26,0);
    rep(i,n){
        cnt[s[i]-'a']++;
    }
    ll now = 0,r = n-1;
    string t;
    t = s;
    while(r-now > 0){
        ll l = s[now]-'a';
        cnt[l]--;
        ll use = -1;
        rep(i,l){
            if (cnt[i] > 0){
                use = i;
                break;
            }
        }
        if (use == -1){
            now++;
            continue;
        }
        while(s[r]-'a' != use){
            cnt[s[r]-'a']--;
            r--;
        }
        swap(t[now],t[r]);
        now++;
        cnt[s[r]-'a']--;
        r--;
    }
    PRINT(t);
}

Submission Info

Submission Time
Task B - Reserve or Reverse
User karudano
Language C++ (GCC 9.2.1)
Score 400
Code Size 2920 Byte
Status AC
Exec Time 13 ms
Memory 3924 KiB

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 400 / 400
Status
AC × 4
AC × 46
Set Name Test Cases
Sample sample_01.txt, sample_02.txt, sample_03.txt, sample_04.txt
All hand_01.txt, hand_02.txt, random_01.txt, random_02.txt, random_03.txt, random_04.txt, random_05.txt, random_06.txt, random_07.txt, random_08.txt, random_09.txt, random_10.txt, random_11.txt, random_12.txt, random_13.txt, random_14.txt, random_15.txt, random_16.txt, random_17.txt, random_18.txt, random_19.txt, random_20.txt, random_21.txt, random_22.txt, random_23.txt, random_24.txt, random_25.txt, random_26.txt, random_27.txt, random_28.txt, random_29.txt, random_30.txt, random_31.txt, random_32.txt, random_33.txt, random_34.txt, random_35.txt, random_36.txt, random_37.txt, random_38.txt, random_39.txt, random_40.txt, sample_01.txt, sample_02.txt, sample_03.txt, sample_04.txt
Case Name Status Exec Time Memory
hand_01.txt AC 13 ms 3736 KiB
hand_02.txt AC 9 ms 3836 KiB
random_01.txt AC 2 ms 3628 KiB
random_02.txt AC 8 ms 3836 KiB
random_03.txt AC 9 ms 3840 KiB
random_04.txt AC 9 ms 3924 KiB
random_05.txt AC 8 ms 3840 KiB
random_06.txt AC 9 ms 3920 KiB
random_07.txt AC 7 ms 3748 KiB
random_08.txt AC 8 ms 3924 KiB
random_09.txt AC 9 ms 3844 KiB
random_10.txt AC 7 ms 3824 KiB
random_11.txt AC 10 ms 3724 KiB
random_12.txt AC 2 ms 3592 KiB
random_13.txt AC 5 ms 3592 KiB
random_14.txt AC 2 ms 3528 KiB
random_15.txt AC 3 ms 3656 KiB
random_16.txt AC 2 ms 3600 KiB
random_17.txt AC 2 ms 3652 KiB
random_18.txt AC 2 ms 3500 KiB
random_19.txt AC 2 ms 3580 KiB
random_20.txt AC 4 ms 3692 KiB
random_21.txt AC 2 ms 3752 KiB
random_22.txt AC 3 ms 3672 KiB
random_23.txt AC 3 ms 3700 KiB
random_24.txt AC 6 ms 3752 KiB
random_25.txt AC 6 ms 3832 KiB
random_26.txt AC 4 ms 3764 KiB
random_27.txt AC 7 ms 3760 KiB
random_28.txt AC 5 ms 3672 KiB
random_29.txt AC 6 ms 3824 KiB
random_30.txt AC 6 ms 3768 KiB
random_31.txt AC 5 ms 3656 KiB
random_32.txt AC 8 ms 3728 KiB
random_33.txt AC 8 ms 3568 KiB
random_34.txt AC 12 ms 3608 KiB
random_35.txt AC 7 ms 3712 KiB
random_36.txt AC 7 ms 3484 KiB
random_37.txt AC 2 ms 3548 KiB
random_38.txt AC 1 ms 3628 KiB
random_39.txt AC 2 ms 3652 KiB
random_40.txt AC 3 ms 3588 KiB
sample_01.txt AC 2 ms 3604 KiB
sample_02.txt AC 2 ms 3584 KiB
sample_03.txt AC 2 ms 3632 KiB
sample_04.txt AC 2 ms 3496 KiB