Submission #3595194


Source Code Expand

#include <limits.h>
#include <algorithm>
#include <bitset>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>

#define int long long
#define REP(i, n) for (int i = 0, i##_len = (n); i < i##_len; ++i)
#define REPS(i, n) for (int i = 1, i##_len = (n); i <= i##_len; ++i)
#define FOR(i, a, b) for (int i = (a), i##_len = (b); i <= i##_len; ++i)
#define REV(i, a, b) for (int i = (a); i >= (b); --i)
#define CLR(a, b) memset((a), (b), sizeof(a))
#define DUMP(x) cout << #x << " = " << (x) << endl;
#define INF 1001001001001001001ll
#define fcout cout << fixed << setprecision(10)

using namespace std;

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

    string A;
    cin >> A;

    int n = A.size();

    vector<int> next(26, 0);
    vector<vector<int>> np(n + 2, vector<int>(26, 0));
    REP(i, 26) np[n][i] = next[i] = n + 1;

    vector<int> dp(n + 2);
    REV(i, n, 0) {
        int tmp = INF;
        REP(j, 26) {
            np[i][j] = next[j];
            int pos = next[j];
            int v = dp[pos];
            if (v < tmp) {
                tmp = v;
            }
        }
        dp[i] = tmp + 1;
        if (i > 0) next[A[i - 1] - 'a'] = i;
    }

    int cur = 0;
    string ans;
    while (cur < n + 1) {
        REP(j, 26) {
            int pos = np[cur][j];
            if (dp[cur] - 1 == dp[pos]) {
                ans += ('a' + j);
                cur = pos;
                break;
            }
        }
    }
    cout << ans << endl;

    return 0;
}

Submission Info

Submission Time
Task E - Don't Be a Subsequence
User tatsumack
Language C++14 (GCC 5.4.1)
Score 600
Code Size 1894 Byte
Status AC
Exec Time 44 ms
Memory 50452 KB

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 600 / 600
Status
AC × 3
AC × 36
Set Name Test Cases
Sample sample1.txt, sample2.txt, sample3.txt
All sample1.txt, sample2.txt, sample3.txt, 1.txt, 10.txt, 11.txt, 12.txt, 13.txt, 14.txt, 15.txt, 16.txt, 17.txt, 18.txt, 19.txt, 2.txt, 20.txt, 21.txt, 22.txt, 23.txt, 24.txt, 25.txt, 26.txt, 27.txt, 28.txt, 29.txt, 3.txt, 30.txt, 4.txt, 5.txt, 6.txt, 7.txt, 8.txt, 9.txt, sample1.txt, sample2.txt, sample3.txt
Case Name Status Exec Time Memory
1.txt AC 1 ms 256 KB
10.txt AC 43 ms 50452 KB
11.txt AC 43 ms 50452 KB
12.txt AC 43 ms 50196 KB
13.txt AC 42 ms 50452 KB
14.txt AC 42 ms 50452 KB
15.txt AC 43 ms 50452 KB
16.txt AC 43 ms 50452 KB
17.txt AC 43 ms 50452 KB
18.txt AC 43 ms 50452 KB
19.txt AC 44 ms 50452 KB
2.txt AC 1 ms 512 KB
20.txt AC 43 ms 50452 KB
21.txt AC 43 ms 50452 KB
22.txt AC 44 ms 50452 KB
23.txt AC 44 ms 50452 KB
24.txt AC 43 ms 50452 KB
25.txt AC 42 ms 50452 KB
26.txt AC 42 ms 50452 KB
27.txt AC 42 ms 50452 KB
28.txt AC 43 ms 50452 KB
29.txt AC 42 ms 50452 KB
3.txt AC 3 ms 2816 KB
30.txt AC 42 ms 50452 KB
4.txt AC 3 ms 2816 KB
5.txt AC 21 ms 25424 KB
6.txt AC 21 ms 25424 KB
7.txt AC 43 ms 50452 KB
8.txt AC 43 ms 50452 KB
9.txt AC 43 ms 50452 KB
sample1.txt AC 1 ms 256 KB
sample2.txt AC 1 ms 256 KB
sample3.txt AC 1 ms 256 KB