Submission #8834343
Source Code Expand
#include <bits/stdc++.h> #define err(args...) {} #ifdef DEBUG #include "_debug.cpp" #endif using namespace std; using ll = long long; using ld = long double; template <typename T> using lim = numeric_limits<T>; template <typename T> istream& operator>>(istream& is, vector<T>& a) { for(T& x : a) { is >> x; } return is; } template <typename X, typename Y> istream& operator>>(istream& is, pair<X, Y>& p) { return is >> p.first >> p.second; } const int N = 200'000; int opt[N+2], nex[N+1][26]; char action[N+2]; int main() { ios_base::sync_with_stdio(false); cin.tie(0); string s; cin >> s; s += 'a'; for(char& c : s) c -= 'a'; fill(begin(nex[s.size()]), end(nex[s.size()]), s.size()); for(int i = s.size() - 1; i >= 0; i--) { for(int c = 0; c < 26; c++) { nex[i][c] = s[i] == c ? i + 1 : nex[i+1][c]; } } for(int i = s.size(); i >= 0; i--) { if(i == s.size()) { opt[i] = 0; } else { opt[i] = lim<int>::max(); for(int c = 0; c < 26; c++) { if(opt[i] > 1 + opt[nex[i][c]]) { opt[i] = 1 + opt[nex[i][c]]; action[i] = c; } } } } for(int i = 0; i < s.size(); i = nex[i][action[i]]) { cout << char('a' + action[i]); } cout << endl; return 0; }
Submission Info
Submission Time | |
---|---|
Task | E - Don't Be a Subsequence |
User | verngutz |
Language | C++14 (GCC 5.4.1) |
Score | 600 |
Code Size | 1424 Byte |
Status | AC |
Exec Time | 26 ms |
Memory | 21908 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 | 25 ms | 21908 KB |
11.txt | AC | 25 ms | 21908 KB |
12.txt | AC | 25 ms | 21780 KB |
13.txt | AC | 25 ms | 21908 KB |
14.txt | AC | 25 ms | 21908 KB |
15.txt | AC | 25 ms | 21908 KB |
16.txt | AC | 25 ms | 21908 KB |
17.txt | AC | 25 ms | 21908 KB |
18.txt | AC | 25 ms | 21908 KB |
19.txt | AC | 25 ms | 21908 KB |
2.txt | AC | 1 ms | 384 KB |
20.txt | AC | 26 ms | 21908 KB |
21.txt | AC | 26 ms | 21908 KB |
22.txt | AC | 26 ms | 21908 KB |
23.txt | AC | 26 ms | 21908 KB |
24.txt | AC | 25 ms | 21908 KB |
25.txt | AC | 25 ms | 21908 KB |
26.txt | AC | 25 ms | 21908 KB |
27.txt | AC | 25 ms | 21908 KB |
28.txt | AC | 25 ms | 21908 KB |
29.txt | AC | 24 ms | 21908 KB |
3.txt | AC | 3 ms | 1280 KB |
30.txt | AC | 25 ms | 21908 KB |
4.txt | AC | 3 ms | 1280 KB |
5.txt | AC | 14 ms | 13008 KB |
6.txt | AC | 14 ms | 13008 KB |
7.txt | AC | 25 ms | 21908 KB |
8.txt | AC | 25 ms | 21908 KB |
9.txt | AC | 25 ms | 21908 KB |
sample1.txt | AC | 1 ms | 256 KB |
sample2.txt | AC | 1 ms | 256 KB |
sample3.txt | AC | 1 ms | 256 KB |