Submission #2846426


Source Code Expand

Copy
// {{{ by shik
#include <bits/stdc++.h>
#pragma GCC diagnostic ignored "-Wunused-result"
#pragma GCC diagnostic ignored "-Wunused-function"
#define SZ(x) ((int)(x).size())
#define ALL(x) begin(x), end(x)
#define REP(i, n) for (int i = 0; i < int(n); i++)
#define REP1(i, a, b) for (int i = (a); i <= int(b); i++)
#define MP make_pair
#define PB push_back
using namespace std;
typedef int64_t LL;
typedef pair<int, int> PII;
typedef vector<int> VI;

namespace { namespace shik {

template<class T> void _R(T &x) { cin >> x; }
void _R(int &x) { scanf("%d", &x); }
void _R(int64_t &x) { scanf("%" SCNd64, &x); }
void _R(double &x) { scanf("%lf", &x); }
void _R(char &x) { scanf(" %c", &x); }
void _R(char *x) { scanf("%s", x); }
void R() {}
template<class T, class... U> void R(T &head, U &... tail) { _R(head); R(tail...); }

template<class T> void _W(const T &x) { cout << x; }
void _W(const int &x) { printf("%d", x); }
void _W(const int64_t &x) { printf("%" PRId64, x); }
void _W(const double &x) { printf("%.16f", x); }
void _W(const char &x) { putchar(x); }
void _W(const char *x) { printf("%s", x); }
template<class T> void _W(const vector<T> &x) { for (auto i = x.begin(); i != x.end(); _W(*i++)) if (i != x.cbegin()) putchar(' '); }
void W() {}
template<class T, class... U> void W(const T &head, const U &... tail) { _W(head); putchar(sizeof...(tail) ? ' ' : '\n'); W(tail...); }

#ifdef SHIK
#include "dump.hpp"
#else
#define dump(...)
#endif

template<class T, class F = less<T>> void sort_uniq(vector<T> &v, F f = F()) { sort(begin(v), end(v), f); v.resize(unique(begin(v), end(v)) - begin(v)); }
template<class T> inline T bit(T x, int i) { return (x >> i) & 1; }
template<class T> inline bool chkmax(T &a, const T &b) { return b > a ? a = b, true : false; }
template<class T> inline bool chkmin(T &a, const T &b) { return b < a ? a = b, true : false; }
template<class T> using MaxHeap = priority_queue<T>;
template<class T> using MinHeap = priority_queue<T, vector<T>, greater<T>>;

// }}}

const int N=3010;
int n,na,nb,a[N],b[N];
char s[2*N];
string dp[N];

void main() {
    R(n,s);
    REP(i,2*n) {
        if ( s[i]=='a' ) a[na++]=i;
        else b[nb++]=i;
    }
    assert(na==n && nb==n);
    for ( int i=n-1; i>=0; i-- ) {
        dp[i]=dp[i+1];
        if ( a[i]<b[i] ) {
            int j=i+1;
            while ( j<n && min(a[j],b[j])<b[i] ) j++;
            chkmax(dp[i],"ab"s+dp[j]);
        } else {
            int mx=max(a[i],b[i]);
            int j=i;
            vector<pair<int,char>> v;
            while ( j<n && min(a[j],b[j])<=mx ) {
                v.PB({a[j],'a'});
                v.PB({b[j],'b'});
                chkmax(mx,max(a[j],b[j]));
                j++;
            }
            sort(ALL(v));
            string z;
            for ( auto &k:v ) z.push_back(k.second);
            chkmax(dp[i],z+dp[j]);
        }
        dump(i,dp[i]);
    }
    W(dp[0]);
}

// {{{ main
}}
int main() { shik::main(); return 0; }
// }}}

Submission Info

Submission Time
Task E - Synchronized Subsequence
User shik
Language C++14 (GCC 5.4.1)
Score 1600
Code Size 3063 Byte
Status
Exec Time 330 ms
Memory 15616 KB

Test Cases

Set Name Score / Max Score Test Cases
Sample 0 / 0 example_0, example_1, example_2, example_3
All 1600 / 1600 bigrand_0, bigrand_1, bigrand_10, bigrand_11, bigrand_12, bigrand_13, bigrand_14, bigrand_2, bigrand_3, bigrand_4, bigrand_5, bigrand_6, bigrand_7, bigrand_8, bigrand_9, bigtoken_0, bigtoken_1, bigtoken_2, bigtoken_3, bigtoken_4, bigtoken_5, bigtoken_6, bigtoken_7, bigtoken_8, bigtoken_9, example_0, example_1, example_2, example_3, koredetanomu_0, koredetanomu_1, koredetanomu_2, koredetanomu_3, koredetanomu_4, koredetanomu_5, koredetanomu_6, koredetanomu_7, lowheight_0, lowheight_1, lowheight_2, lowheight_3, lowheight_4, lowheight_5, lowheight_6, lowheight_7, lowheight_8, lowheight_9, midtoken_0, midtoken_1, midtoken_2, midtoken_3, midtoken_4, midtoken_5, midtoken_6, midtoken_7, midtoken_8, midtoken_9, midtoken_sorted_0, midtoken_sorted_1, midtoken_sorted_2, midtoken_sorted_3, midtoken_sorted_4, midtoken_sorted_5, midtoken_sorted_6, midtoken_sorted_7, midtoken_sorted_8, midtoken_sorted_9, smallrand_0, smallrand_1, smallrand_2, smallrand_3, smallrand_4, smalltoken_0, smalltoken_1, smalltoken_2, smalltoken_3, smalltoken_4, smalltoken_5, smalltoken_6, smalltoken_7, smalltoken_8, smalltoken_9, smalltoken_sorted_0, smalltoken_sorted_1, smalltoken_sorted_2, smalltoken_sorted_3, smalltoken_sorted_4, smalltoken_sorted_5, smalltoken_sorted_6, smalltoken_sorted_7, smalltoken_sorted_8, smalltoken_sorted_9, specialtoken_0, specialtoken_1, specialtoken_2, specialtoken_3, specialtoken_4, specialtoken_5, specialtoken_sorted_0, specialtoken_sorted_1, specialtoken_sorted_2, specialtoken_sorted_3, specialtoken_sorted_4, specialtoken_sorted_5
Case Name Status Exec Time Memory
bigrand_0 3 ms 256 KB
bigrand_1 3 ms 384 KB
bigrand_10 51 ms 512 KB
bigrand_11 10 ms 384 KB
bigrand_12 2 ms 256 KB
bigrand_13 32 ms 384 KB
bigrand_14 2 ms 256 KB
bigrand_2 84 ms 384 KB
bigrand_3 2 ms 256 KB
bigrand_4 32 ms 384 KB
bigrand_5 2 ms 256 KB
bigrand_6 3 ms 256 KB
bigrand_7 63 ms 384 KB
bigrand_8 23 ms 384 KB
bigrand_9 177 ms 640 KB
bigtoken_0 305 ms 512 KB
bigtoken_1 2 ms 384 KB
bigtoken_2 282 ms 512 KB
bigtoken_3 2 ms 384 KB
bigtoken_4 273 ms 512 KB
bigtoken_5 2 ms 384 KB
bigtoken_6 330 ms 768 KB
bigtoken_7 2 ms 384 KB
bigtoken_8 303 ms 768 KB
bigtoken_9 2 ms 384 KB
example_0 1 ms 256 KB
example_1 1 ms 256 KB
example_2 1 ms 256 KB
example_3 1 ms 256 KB
koredetanomu_0 41 ms 384 KB
koredetanomu_1 41 ms 384 KB
koredetanomu_2 41 ms 384 KB
koredetanomu_3 41 ms 384 KB
koredetanomu_4 41 ms 384 KB
koredetanomu_5 41 ms 384 KB
koredetanomu_6 41 ms 384 KB
koredetanomu_7 41 ms 384 KB
lowheight_0 208 ms 15616 KB
lowheight_1 3 ms 2176 KB
lowheight_2 260 ms 384 KB
lowheight_3 3 ms 1664 KB
lowheight_4 241 ms 512 KB
lowheight_5 3 ms 1280 KB
lowheight_6 281 ms 384 KB
lowheight_7 2 ms 1024 KB
lowheight_8 274 ms 384 KB
lowheight_9 2 ms 768 KB
midtoken_0 2 ms 256 KB
midtoken_1 3 ms 256 KB
midtoken_2 3 ms 256 KB
midtoken_3 3 ms 256 KB
midtoken_4 4 ms 256 KB
midtoken_5 4 ms 256 KB
midtoken_6 4 ms 256 KB
midtoken_7 4 ms 256 KB
midtoken_8 4 ms 256 KB
midtoken_9 7 ms 256 KB
midtoken_sorted_0 3 ms 1280 KB
midtoken_sorted_1 3 ms 896 KB
midtoken_sorted_2 3 ms 768 KB
midtoken_sorted_3 3 ms 768 KB
midtoken_sorted_4 4 ms 640 KB
midtoken_sorted_5 4 ms 640 KB
midtoken_sorted_6 4 ms 640 KB
midtoken_sorted_7 5 ms 512 KB
midtoken_sorted_8 5 ms 512 KB
midtoken_sorted_9 6 ms 512 KB
smallrand_0 1 ms 256 KB
smallrand_1 1 ms 256 KB
smallrand_2 1 ms 256 KB
smallrand_3 1 ms 256 KB
smallrand_4 1 ms 256 KB
smalltoken_0 3 ms 2304 KB
smalltoken_1 2 ms 640 KB
smalltoken_2 2 ms 384 KB
smalltoken_3 2 ms 256 KB
smalltoken_4 2 ms 256 KB
smalltoken_5 2 ms 256 KB
smalltoken_6 2 ms 256 KB
smalltoken_7 2 ms 256 KB
smalltoken_8 2 ms 256 KB
smalltoken_9 2 ms 256 KB
smalltoken_sorted_0 7 ms 10496 KB
smalltoken_sorted_1 5 ms 5248 KB
smalltoken_sorted_2 4 ms 3456 KB
smalltoken_sorted_3 4 ms 2688 KB
smalltoken_sorted_4 3 ms 2304 KB
smalltoken_sorted_5 3 ms 1920 KB
smalltoken_sorted_6 3 ms 1664 KB
smalltoken_sorted_7 3 ms 1536 KB
smalltoken_sorted_8 3 ms 1408 KB
smalltoken_sorted_9 3 ms 1280 KB
specialtoken_0 4 ms 512 KB
specialtoken_1 4 ms 256 KB
specialtoken_2 4 ms 256 KB
specialtoken_3 4 ms 256 KB
specialtoken_4 4 ms 256 KB
specialtoken_5 5 ms 256 KB
specialtoken_sorted_0 4 ms 1280 KB
specialtoken_sorted_1 4 ms 1024 KB
specialtoken_sorted_2 5 ms 896 KB
specialtoken_sorted_3 5 ms 640 KB
specialtoken_sorted_4 5 ms 768 KB
specialtoken_sorted_5 5 ms 640 KB