Submission #2449563


Source Code Expand

Copy
#include <bits/stdc++.h>
using std::cout;
using std::endl;
using std::cin;

int main(){
	std::string s; cin >> s;
	std::vector<int> li(26, s.size() + 1);
	std::vector<int> dp(s.size() + 2, 1e9);
	std::vector<std::pair<char, int>> ans(s.size() + 1);
	dp[s.size() + 1] = 0; dp[s.size()] = 1;
	ans[s.size()] = {'a', s.size() + 1};
	
	for(int i = s.size() - 1; i >= 0; i--){
		li[s[i] - 'a'] = i + 1;
		
		for(int j = 0; j < 26; j++){
			if(dp[li[j]] + 1 < dp[i]){
				dp[i] = dp[li[j]] + 1;
				ans[i] = {'a' + j, li[j]};
			}
		}
	}
	
	int pos = 0;
	while(pos <= s.size()){
		cout << ans[pos].first;
		pos = ans[pos].second;
	}
	cout << endl;
	return 0;
}

Submission Info

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