Submission #1536027


Source Code Expand

Copy
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;

int calc(vector<vector<int>> &v, vector<int> &dp, vector<int> &next, int now = 0){
	if(now == dp.size()) return 1;
	if(dp.size() < now) return 0;
	if(dp[now] != 1 << 30) return dp[now];
	for(int i = 0; i < 26; i++){
		int length = calc(v, dp, next, *lower_bound(v[i].begin(), v[i].end(), now) + 1) + 1;
		if(length < dp[now]){
			dp[now] = length;
			next[now] = i;
		}
	}
	return dp[now];
}

int main(){
	string s;
	cin >> s;
	vector<vector<int>> v(26);
	for(int i = 0; i < s.size(); i++){
		v[s[i] - 'a'].emplace_back(i);
	}
	for(auto &vv:v) vv.emplace_back(s.size());
	vector<int> dp(s.size(), 1 << 30), next(s.size(), -1);
	calc(v, dp, next);
	for(int i = 0; i < next.size(); i = *lower_bound(v[next[i]].begin(), v[next[i]].end(), i) + 1){
		cout << char('a' + next[i]);
	}
	cout << endl;
}

Submission Info

Submission Time
Task E - Don't Be a Subsequence
User jbyxm
Language C++14 (GCC 5.4.1)
Score 600
Code Size 908 Byte
Status
Exec Time 158 ms
Memory 3716 KB

Test Cases

Set Name Score / Max Score Test Cases
Sample 0 / 0 sample1.txt, sample2.txt, sample3.txt
All 600 / 600 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 1 ms 256 KB
10.txt 157 ms 3588 KB
11.txt 155 ms 3588 KB
12.txt 155 ms 3588 KB
13.txt 157 ms 3460 KB
14.txt 157 ms 3588 KB
15.txt 156 ms 3460 KB
16.txt 157 ms 3588 KB
17.txt 156 ms 3588 KB
18.txt 157 ms 3588 KB
19.txt 158 ms 3588 KB
2.txt 2 ms 256 KB
20.txt 156 ms 3588 KB
21.txt 157 ms 3460 KB
22.txt 155 ms 3716 KB
23.txt 139 ms 3588 KB
24.txt 156 ms 3588 KB
25.txt 156 ms 3588 KB
26.txt 156 ms 3588 KB
27.txt 156 ms 3460 KB
28.txt 157 ms 3588 KB
29.txt 156 ms 3588 KB
3.txt 8 ms 384 KB
30.txt 156 ms 3588 KB
4.txt 8 ms 384 KB
5.txt 76 ms 1920 KB
6.txt 75 ms 1920 KB
7.txt 156 ms 3588 KB
8.txt 156 ms 3588 KB
9.txt 155 ms 3460 KB
sample1.txt 1 ms 256 KB
sample2.txt 1 ms 256 KB
sample3.txt 1 ms 256 KB