Submission #1792021
Source Code Expand
#include <cstdio> #include <climits> #include <cassert> #include <cmath> #include <iostream> #include <string> #include <algorithm> #include <numeric> #include <functional> #include <tuple> #include <list> #include <map> #include <queue> #include <stack> #include <set> #include <vector> #define REP(i,s,n) for(int i=(int)(s);i<(int)(n);i++) #define FOR(x,xs) for(auto &x: xs) using namespace std; typedef long long ll; typedef pair<int,int> PI; typedef pair<ll,ll> PL; typedef vector<int> VI; typedef vector<ll> VL; const int M = 26; int main() { ios::sync_with_stdio(false); string a; cin >> a; int n = a.size(); VI sep; vector<bool> app(M, false); int appcount = 0; vector<VI> pos(M); for(int i = n-1; i >= 0; i--) { if(!app[a[i]-'a']) { app[a[i]-'a'] = true; appcount++; if(appcount == M) { sep.push_back(i); app.assign(M, false); appcount = 0; } } } if(sep.empty()) { REP(i,0,M) { if(!app[i]) { cout << (char)('a'+i) << endl; return 0; } } } reverse(sep.begin(), sep.end()); sep.push_back(n); REP(i,0,n) { pos[a[i]-'a'].push_back(i); } int len = sep.size(); int used = -1; string ans; REP(i,0,len) { REP(c,0,M) { auto cp = lower_bound(pos[c].begin(), pos[c].end(), used); if(cp == pos[c].end() || *cp >= sep[i]) { ans.push_back('a' + c); used = *cp + 1; break; } } } cout << ans << endl; return 0; }
Submission Info
Submission Time | |
---|---|
Task | E - Don't Be a Subsequence |
User | minus3theta |
Language | C++14 (GCC 5.4.1) |
Score | 600 |
Code Size | 1583 Byte |
Status | AC |
Exec Time | 5 ms |
Memory | 1428 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 | 5 ms | 1428 KB |
11.txt | AC | 5 ms | 1428 KB |
12.txt | AC | 5 ms | 1428 KB |
13.txt | AC | 5 ms | 1428 KB |
14.txt | AC | 5 ms | 1428 KB |
15.txt | AC | 5 ms | 1428 KB |
16.txt | AC | 5 ms | 1428 KB |
17.txt | AC | 5 ms | 1428 KB |
18.txt | AC | 5 ms | 1428 KB |
19.txt | AC | 5 ms | 1428 KB |
2.txt | AC | 1 ms | 256 KB |
20.txt | AC | 4 ms | 1428 KB |
21.txt | AC | 4 ms | 1428 KB |
22.txt | AC | 4 ms | 1428 KB |
23.txt | AC | 4 ms | 1428 KB |
24.txt | AC | 4 ms | 1300 KB |
25.txt | AC | 3 ms | 1428 KB |
26.txt | AC | 3 ms | 1428 KB |
27.txt | AC | 3 ms | 1428 KB |
28.txt | AC | 3 ms | 1428 KB |
29.txt | AC | 3 ms | 1428 KB |
3.txt | AC | 1 ms | 384 KB |
30.txt | AC | 3 ms | 1428 KB |
4.txt | AC | 1 ms | 384 KB |
5.txt | AC | 3 ms | 848 KB |
6.txt | AC | 3 ms | 848 KB |
7.txt | AC | 5 ms | 1428 KB |
8.txt | AC | 5 ms | 1428 KB |
9.txt | AC | 5 ms | 1428 KB |
sample1.txt | AC | 1 ms | 256 KB |
sample2.txt | AC | 1 ms | 256 KB |
sample3.txt | AC | 1 ms | 256 KB |