Submission #1984454
Source Code Expand
#include <iostream> #include <climits> #include <iostream> #include <string> #include <vector> #include <queue> #include <stack> #include <map> #include <algorithm> #include <numeric> #include <functional> #include <set> #include <sstream> #include <cstdio> #include <cstdlib> #include <cstring> #include <cmath> #include <cctype> #include <climits> #include <fstream> #include <bitset> #include <time.h> #include <random> #include <assert.h> #include <signal.h> #include <stdlib.h> #include <stdio.h> #include <signal.h> #include <stdexcept> #include <iomanip> #define LL long long #define VI vector<int> #define VL vector<long long> #define FOR(i,a,b) for(int i= (a); i<((int)b); ++i) #define RFOR(i,a) for(int i=(a); i >= 0; --i) #define FOE(i,a) for(auto i : a) #define ALL(c) (c).begin(), (c).end() #define RALL(c) (c).rbegin(), (c).rend() #define DUMP(x) cerr << #x << " = " << (x) << endl; #define SUM(x) std::accumulate(ALL(x), 0LL) #define MIN(v) *std::min_element(v.begin(), v.end()) #define MAX(v) *std::max_element(v.begin(), v.end()) #define EXIST(v,x) (std::find(v.begin(), v.end(), x) != v.end()) #define BIT(n) (1LL<<(n)) #define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end()); #define EPS 1e-14 using namespace std; int main() { string A; cin >> A; auto n = A.size(); // iの後ろではじめでてくる文字cのindex vector<vector<int>> next(n + 1, vector<int>(26, n)); for(int i = n - 1; i >= 0; --i) { int c = A[i] - 'a'; next[i] = next[i + 1]; next[i][c] = i; } vector<int> dp(n + 2, 0); dp[n] = 1; for(int i = n - 1; i >= 0; --i) { int l = INT_MAX; FOR(j, 0, 26) { l = min(l, dp[next[i][j] + 1] + 1); } dp[i] = l; } string ans; int p = 0; for (int i = dp[0] - 1; i >= 0; --i) { FOR(j, 0, 26) { if (dp[next[p][j] + 1] == i) { ans += char('a' + j); p = next[p][j] + 1; break; } } } cout << ans << endl; return 0; }
Submission Info
Submission Time | |
---|---|
Task | E - Don't Be a Subsequence |
User | MitI_7 |
Language | C++14 (GCC 5.4.1) |
Score | 600 |
Code Size | 2170 Byte |
Status | AC |
Exec Time | 37 ms |
Memory | 27780 KB |
Judge Result
Set Name | Sample | All | ||||
---|---|---|---|---|---|---|
Score / Max Score | 0 / 0 | 600 / 600 | ||||
Status |
|
|
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 | 36 ms | 27780 KB |
11.txt | AC | 36 ms | 27780 KB |
12.txt | AC | 36 ms | 27652 KB |
13.txt | AC | 36 ms | 27780 KB |
14.txt | AC | 37 ms | 27780 KB |
15.txt | AC | 36 ms | 27780 KB |
16.txt | AC | 36 ms | 27780 KB |
17.txt | AC | 37 ms | 27780 KB |
18.txt | AC | 37 ms | 27780 KB |
19.txt | AC | 37 ms | 27780 KB |
2.txt | AC | 1 ms | 384 KB |
20.txt | AC | 37 ms | 27780 KB |
21.txt | AC | 36 ms | 27780 KB |
22.txt | AC | 37 ms | 27780 KB |
23.txt | AC | 37 ms | 27780 KB |
24.txt | AC | 36 ms | 27780 KB |
25.txt | AC | 36 ms | 27780 KB |
26.txt | AC | 36 ms | 27780 KB |
27.txt | AC | 36 ms | 27780 KB |
28.txt | AC | 36 ms | 27780 KB |
29.txt | AC | 36 ms | 27780 KB |
3.txt | AC | 4 ms | 1664 KB |
30.txt | AC | 36 ms | 27780 KB |
4.txt | AC | 3 ms | 1664 KB |
5.txt | AC | 19 ms | 14080 KB |
6.txt | AC | 19 ms | 14080 KB |
7.txt | AC | 37 ms | 27780 KB |
8.txt | AC | 36 ms | 27780 KB |
9.txt | AC | 36 ms | 27780 KB |
sample1.txt | AC | 1 ms | 256 KB |
sample2.txt | AC | 1 ms | 256 KB |
sample3.txt | AC | 1 ms | 256 KB |