Submission #3589230
Source Code Expand
#include <iostream>
#include <fstream>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <algorithm>
#include <numeric>
#include <functional>
#include <string>
#include <vector>
#include <bitset>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <deque>
using namespace std;
using ll = long long;
template<class T> using V = vector<T>;
template<class T, class U> using P = pair<T, U>;
#define REP(i,n) for(int i = 0; i < int(n); i++)
#define FOR(i, m, n) for(int i = int(m);i < int(n);i++)
#define ALL(obj) (obj).begin(),(obj).end()
const ll MOD = (ll)1e9 + 7;
const ll HINF = (ll)1e18;
const ll LINF = (ll)1e9;
const long double PI = 3.1415926535897932384626433;
vector<int> dy = { 0,0,1,-1 };
vector<int> dx = { 1,-1,0,0 };
template<class T> void corner(bool flg, T hoge) {
if (flg) {
cout << hoge << endl;
exit(0);
}
else return;
}
template <class T, class U>ostream &operator<<(ostream &o, const map<T, U>&obj) {
o << "{"; for (auto &x : obj) o << " {" << x.first << " : " << x.second << "}" << ","; o << " }"; return o;
}
template <class T>ostream &operator<<(ostream &o, const set<T>&obj) {
o << "{"; for (auto itr = obj.begin(); itr != obj.end(); ++itr) o << (itr != obj.begin() ? ", " : "") << *itr; o << "}"; return o;
}
template <class T>ostream &operator<<(ostream &o, const vector<T>&obj) {
o << "{"; for (int i = 0; i < (int)obj.size(); ++i)o << (i > 0 ? ", " : "") << obj[i]; o << "}"; return o;
}
template <class T, class U>ostream &operator<<(ostream &o, const pair<T, U>&obj) {
o << "{" << obj.first << ", " << obj.second << "}"; return o;
}
template <template <class tmp> class T, class U> ostream &operator<<(ostream &o, const T<U> &obj) {
o << "{"; for (auto itr = obj.begin(); itr != obj.end(); ++itr)o << (itr != obj.begin() ? ", " : "") << *itr; o << "}"; return o;
}
void print(void) {
cout << endl;
}
template <class Head> void print(Head&& head) {
cout << head;
print();
}
template <class Head, class... Tail> void print(Head&& head, Tail&&... tail) {
cout << head << " ";
print(forward<Tail>(tail)...);
}
void YN(bool flg) {
cout << ((flg) ? "YES" : "NO") << endl;
}
void Yn(bool flg) {
cout << ((flg) ? "Yes" : "No") << endl;
}
void yn(bool flg) {
cout << ((flg) ? "yes" : "no") << endl;
}
V<V< int >> edge(26, V< int >(2 * 100000 + 10));
V<V<P<int, string>>> cost(26,V<P<int,string>>(2 * 100000 + 1,{LINF,""}));
int N;
void Dijkstra() {
priority_queue<P<P<int, string>, P<int, int>>, V<P<P<int, string>, P<int, int>>>, greater<P<P<int, string>, P<int, int>>>> pq;
cost[0][0] = { 0,"" };
pq.push({ {0,""},{0,0} });
while(!pq.empty()){
int cost_from = pq.top().first.first;
string str_from = pq.top().first.second;
int alp_from = pq.top().second.first;
int idx_from = pq.top().second.second;
pq.pop();
if (idx_from == N - 1) continue;
REP(i, 26) {
int cost_to, alp_to, idx_to;
string str_to;
char ch = char(int(i + 'a'));
cost_to = cost_from + 1;
alp_to = i;
idx_to = edge[i][idx_from];
str_to = str_from;
str_to.push_back(ch);
if ((cost_to < cost[alp_to][idx_to].first) || (cost_to == cost[alp_to][idx_to].first && str_to < cost[alp_to][idx_to].second)) {
cost[alp_to][idx_to] = { cost_to,str_to };
pq.push({ {cost_to,str_to},{alp_to,idx_to} });
}
}
}
return;
}
int main() {
string s; cin >> s;
s = "." + s + ".";
N = s.size();
REP(i,26){
char ch = char(int(i + 'a'));
int idx = N-1;
for (int j = N-2; 0 <= j; --j) {
edge[i][j] = idx;
if (s[j] == ch)idx = j;
}
}
Dijkstra();
map<int, V<string>> mp;
REP(i, 26) mp[cost[i][N - 1].first].push_back(cost[i][N - 1].second);
for(auto u:mp){
sort(ALL(u.second));
cout << u.second[0] << endl;
return 0;
}
return 0;
}
Submission Info
Submission Time |
|
Task |
E - Don't Be a Subsequence |
User |
ningenMe |
Language |
C++14 (GCC 5.4.1) |
Score |
0 |
Code Size |
3909 Byte |
Status |
RE |
Exec Time |
2188 ms |
Memory |
1166904 KB |
Judge Result
Set Name |
Sample |
All |
Score / Max Score |
0 / 0 |
0 / 600 |
Status |
|
AC |
× 12 |
TLE |
× 4 |
MLE |
× 5 |
RE |
× 15 |
|
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 |
64 ms |
105072 KB |
10.txt |
RE |
1004 ms |
405176 KB |
11.txt |
MLE |
1047 ms |
403512 KB |
12.txt |
MLE |
941 ms |
397368 KB |
13.txt |
RE |
995 ms |
402616 KB |
14.txt |
RE |
994 ms |
398776 KB |
15.txt |
RE |
999 ms |
401464 KB |
16.txt |
RE |
994 ms |
403128 KB |
17.txt |
MLE |
1220 ms |
635064 KB |
18.txt |
MLE |
1481 ms |
717880 KB |
19.txt |
MLE |
1691 ms |
909748 KB |
2.txt |
AC |
71 ms |
105196 KB |
20.txt |
TLE |
2154 ms |
1124664 KB |
21.txt |
TLE |
2182 ms |
1153336 KB |
22.txt |
TLE |
2187 ms |
1166904 KB |
23.txt |
TLE |
2188 ms |
1166392 KB |
24.txt |
RE |
803 ms |
207672 KB |
25.txt |
RE |
711 ms |
128952 KB |
26.txt |
RE |
737 ms |
168888 KB |
27.txt |
RE |
715 ms |
137144 KB |
28.txt |
RE |
709 ms |
143288 KB |
29.txt |
RE |
774 ms |
217016 KB |
3.txt |
AC |
95 ms |
105072 KB |
30.txt |
RE |
777 ms |
212024 KB |
4.txt |
AC |
95 ms |
105072 KB |
5.txt |
AC |
409 ms |
179128 KB |
6.txt |
AC |
459 ms |
179256 KB |
7.txt |
RE |
1045 ms |
409400 KB |
8.txt |
RE |
1009 ms |
402360 KB |
9.txt |
RE |
1039 ms |
405176 KB |
sample1.txt |
AC |
71 ms |
105072 KB |
sample2.txt |
AC |
70 ms |
105072 KB |
sample3.txt |
AC |
71 ms |
105072 KB |