Submission #1984453
Source Code Expand
#include <cassert> #include <cstdio> #include <cstring> #include <iostream> #include <algorithm> #include <map> #include <vector> #define REP(i, n) for(int i = 0; i < (int)(n); ++i) #define FOR(i, c) for(__typeof((c).begin()) i = (c).begin(); i != (c).end(); ++i) using namespace std; typedef long long ll; char buf[200000+10]; int nextOccur[26][200000+10]; int lenFrom[200000+10]; int lastFrom[200000+10]; const int INF = 1000000000; int main(void) { scanf("%s", buf); int n = strlen(buf); REP(c, 26) { nextOccur[c][n] = INF; for(int i = n-1; i >= 0; --i) { if(buf[i] == 'a'+c) { nextOccur[c][i] = i; } else { nextOccur[c][i] = nextOccur[c][i+1]; } } } for(int i = n-1; i >= 0; --i) { int& maxi = lastFrom[i]; maxi = -1; REP(c, 26) { maxi = max(nextOccur[c][i], maxi); } if(maxi == INF){ lenFrom[i] = 0; } else { lenFrom[i] = lenFrom[maxi+1]+1; } } for(int pos = 0; ; ) { int minLen = INF; int minC = -1; REP(c, 26) { int len = nextOccur[c][pos] == INF ? -1 : lenFrom[nextOccur[c][pos]+1]; if(len < minLen) { minLen = len; minC = c; } } printf("%c", 'a'+minC); if(minLen < 0) { break; } else { pos = nextOccur[minC][pos]+1; } } puts(""); return 0; }
Submission Info
Submission Time | |
---|---|
Task | E - Don't Be a Subsequence |
User | ush |
Language | C++14 (GCC 5.4.1) |
Score | 600 |
Code Size | 1426 Byte |
Status | AC |
Exec Time | 22 ms |
Memory | 22272 KB |
Compile Error
./Main.cpp: In function ‘int main()’: ./Main.cpp:22:19: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result] scanf("%s", buf); ^
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 | 5 ms | 18688 KB |
10.txt | AC | 21 ms | 22272 KB |
11.txt | AC | 21 ms | 22272 KB |
12.txt | AC | 21 ms | 22272 KB |
13.txt | AC | 21 ms | 22272 KB |
14.txt | AC | 21 ms | 22272 KB |
15.txt | AC | 21 ms | 22272 KB |
16.txt | AC | 21 ms | 22272 KB |
17.txt | AC | 22 ms | 22272 KB |
18.txt | AC | 22 ms | 22272 KB |
19.txt | AC | 22 ms | 22272 KB |
2.txt | AC | 5 ms | 18688 KB |
20.txt | AC | 21 ms | 22272 KB |
21.txt | AC | 21 ms | 22272 KB |
22.txt | AC | 22 ms | 22272 KB |
23.txt | AC | 21 ms | 22272 KB |
24.txt | AC | 21 ms | 22272 KB |
25.txt | AC | 21 ms | 22272 KB |
26.txt | AC | 21 ms | 22272 KB |
27.txt | AC | 21 ms | 22272 KB |
28.txt | AC | 21 ms | 22272 KB |
29.txt | AC | 21 ms | 22272 KB |
3.txt | AC | 5 ms | 18816 KB |
30.txt | AC | 21 ms | 22272 KB |
4.txt | AC | 5 ms | 18816 KB |
5.txt | AC | 13 ms | 20608 KB |
6.txt | AC | 13 ms | 20608 KB |
7.txt | AC | 21 ms | 22272 KB |
8.txt | AC | 21 ms | 22272 KB |
9.txt | AC | 21 ms | 22272 KB |
sample1.txt | AC | 5 ms | 18688 KB |
sample2.txt | AC | 5 ms | 18688 KB |
sample3.txt | AC | 5 ms | 18688 KB |