Submission #1778949


Source Code Expand

#include <bits/stdc++.h>
#define rep(n) for(lint I = 0; (I) < (lint)(n); ++(I))
#define repeat(i, n) for(lint i = 0; (i) < (lint)(n); ++(i))
#define repeat_to(i, n) for(lint i = 0; (i) <= (lint)(n); ++(i))
#define repeat_from(i, m, n) for(lint i = (m); (i) < (lint)(n); ++(i))
#define repeat_from_to(i, m, n) for(lint i = (m); (i) <= (lint)(n); ++(i))
#define repeat_reverse_from_to(i, m, n) for(lint i = (m); (i) >= (lint)(n); --(i))
#define el cout<<endl
#define dump(x) cout<<" "<<#x<<"="<<x
#define vdump(v) for(size_t I=0; I<v.size(); ++I){cout<<" "<<#v<<"["<<I<<"]="<<v[I];} cout<<endl
using namespace std;
using lint = long long;
using ld = long double;

int main(void) {
    string s;
    cin >> s;
    int n = s.length();
    
    vector<int> dp(n + 2, 0);
    vector<pair<int, char>> dp_pos(n + 1);
    
    map<char, int> next;
    for (char c = 'a'; c <= 'z'; ++c) next[c] = n;
    
    dp[n + 1] = 0;
    dp[n] = 1;
    repeat_reverse_from_to (i, n - 1, 0) {
        next[s[i]] = i;
        int m = n;
        for (char c = 'z'; c >= 'a'; --c) {
            if (dp[ next[c] + 1 ] <= m) {
                m = dp[ next[c] + 1 ] + 1;
                dp_pos[i].first = next[c] + 1;
                dp_pos[i].second = c;
            }
        }
        dp[i] = m + 1;
    }
    
    //repeat_from_to(i, 0, n) {cout << "dp_pos[" << i << "]=(" << dp_pos[i].first << "," << dp_pos[i].second << ")" << endl;}
    
    int pos = 0;
    while (pos < n) {
        cout << dp_pos[pos].second;
        pos = dp_pos[pos].first;
    }
    cout << endl;
}

Submission Info

Submission Time
Task E - Don't Be a Subsequence
User maphylageo
Language C++14 (GCC 5.4.1)
Score 600
Code Size 1599 Byte
Status AC
Exec Time 93 ms
Memory 3076 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 79 ms 2948 KB
11.txt AC 79 ms 2948 KB
12.txt AC 79 ms 2948 KB
13.txt AC 79 ms 2948 KB
14.txt AC 79 ms 2948 KB
15.txt AC 79 ms 2948 KB
16.txt AC 79 ms 2948 KB
17.txt AC 82 ms 2948 KB
18.txt AC 84 ms 2948 KB
19.txt AC 88 ms 2948 KB
2.txt AC 2 ms 256 KB
20.txt AC 92 ms 2948 KB
21.txt AC 93 ms 2948 KB
22.txt AC 93 ms 2948 KB
23.txt AC 93 ms 2948 KB
24.txt AC 77 ms 2948 KB
25.txt AC 80 ms 2948 KB
26.txt AC 82 ms 2948 KB
27.txt AC 82 ms 2948 KB
28.txt AC 75 ms 2948 KB
29.txt AC 85 ms 2948 KB
3.txt AC 5 ms 384 KB
30.txt AC 89 ms 2948 KB
4.txt AC 5 ms 384 KB
5.txt AC 40 ms 1664 KB
6.txt AC 40 ms 1664 KB
7.txt AC 79 ms 3076 KB
8.txt AC 79 ms 2948 KB
9.txt AC 79 ms 2948 KB
sample1.txt AC 1 ms 256 KB
sample2.txt AC 1 ms 256 KB
sample3.txt AC 1 ms 256 KB