Submission #2522346
Source Code Expand
import std.stdio, std.string, std.conv; import std.range, std.algorithm, std.array, std.typecons, std.container; import std.math, std.numeric, core.bitop; enum inf = 1<<30; enum full = (1<<26) - 1; void main() { string s; scan(s); int n = s.length.to!int; auto dp = new int[](n + 1); dp[n] = 1; auto next = new int[][](n + 1, 26); fillAll(next, inf); int b = 0; foreach_reverse (i ; 0 .. n) { b |= (1<<(s[i] - 'a')); if (b == full) { dp[i] = dp[i+1] + 1; b = 0; } else { dp[i] = dp[i+1]; } foreach (j ; 0 .. 26) { if (s[i] - 'a' == j) { next[i][j] = i; } else { next[i][j] = next[i+1][j]; } } } debug { writeln(dp); writeln; writefln("%(%s\n%)", next); } auto ans = new char[](dp[0]); ans[] = '#'; int pos = 0; foreach (i ; 0 .. dp[0]) { foreach (c ; 0 .. 26) { if (next[pos][c] == inf) { ans[i] = ('a' + c).to!char; break; } if (dp[pos] == dp[next[pos][c]+1] + 1) { ans[i] = ('a' + c).to!char; pos = next[pos][c]+1; break; } } } writeln(ans); } void scan(T...)(ref T args) { import std.stdio : readln; import std.algorithm : splitter; import std.conv : to; import std.range.primitives; auto line = readln().splitter(); foreach (ref arg; args) { arg = line.front.to!(typeof(arg)); line.popFront(); } assert(line.empty); } void fillAll(R, T)(ref R arr, T value) { static if (is(typeof(arr[] = value))) { arr[] = value; } else { foreach (ref e; arr) { fillAll(e, value); } } }
Submission Info
Submission Time | |
---|---|
Task | E - Don't Be a Subsequence |
User | nanae |
Language | D (DMD64 v2.070.1) |
Score | 600 |
Code Size | 2074 Byte |
Status | AC |
Exec Time | 59 ms |
Memory | 35256 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 | 58 ms | 31800 KB |
11.txt | AC | 59 ms | 32440 KB |
12.txt | AC | 56 ms | 31288 KB |
13.txt | AC | 59 ms | 33592 KB |
14.txt | AC | 58 ms | 31928 KB |
15.txt | AC | 58 ms | 33592 KB |
16.txt | AC | 59 ms | 32440 KB |
17.txt | AC | 59 ms | 32824 KB |
18.txt | AC | 59 ms | 34360 KB |
19.txt | AC | 59 ms | 32440 KB |
2.txt | AC | 1 ms | 380 KB |
20.txt | AC | 59 ms | 32312 KB |
21.txt | AC | 59 ms | 33336 KB |
22.txt | AC | 59 ms | 34232 KB |
23.txt | AC | 59 ms | 31928 KB |
24.txt | AC | 58 ms | 35256 KB |
25.txt | AC | 58 ms | 31928 KB |
26.txt | AC | 58 ms | 32184 KB |
27.txt | AC | 58 ms | 32312 KB |
28.txt | AC | 58 ms | 33208 KB |
29.txt | AC | 59 ms | 33336 KB |
3.txt | AC | 4 ms | 1916 KB |
30.txt | AC | 58 ms | 32952 KB |
4.txt | AC | 4 ms | 1916 KB |
5.txt | AC | 28 ms | 17432 KB |
6.txt | AC | 29 ms | 17816 KB |
7.txt | AC | 59 ms | 32440 KB |
8.txt | AC | 59 ms | 34232 KB |
9.txt | AC | 59 ms | 32440 KB |
sample1.txt | AC | 1 ms | 256 KB |
sample2.txt | AC | 1 ms | 256 KB |
sample3.txt | AC | 1 ms | 256 KB |