Submission #1531139
Source Code Expand
#include <bits/stdc++.h> using namespace std; const int maxn = (int)2*1e5+10; const int size = 26; const int inf = (int)1e9+7; int dp[maxn], vis[maxn]; int nxt[maxn][size]; char A[maxn]; int n; //////////////辅助函数///////////// int id(char c) { return c-'a'; } int f(int x) { if (x > n) return 0; int &ans = dp[x]; if (vis[x]) return ans; vis[x] = 1; ans = inf; for (int i=0; i<size; i++) { ans=min(ans, f(nxt[x][i]+1)+1); //if (x == 0) printf("%c %d\n", 'a'+i, ans); } return ans; } void print_ans(int x) { if (x > n) return ; for (int i=0; i<size; i++) if (dp[x]==dp[nxt[x][i]+1]+1) { putchar(i+'a'); print_ans(nxt[x][i]+1); break; } } //////////////主要函数///////////// void init() { scanf("%s", A); n = strlen(A); for (int i=0; i<size; i++) nxt[n][i] = n; for (int i=n-1; i>=0; i--) for (int j=0; j<size; j++) { if (id(A[i]) == j) nxt[i][j] = i; else nxt[i][j] = nxt[i+1][j]; } } void solve() { f(0); //for (int i=0; i<n; i++) printf("%d ", dp[i]); //printf("\n"); print_ans(0); putchar('\n'); } int main() { init(); solve(); return 0; }
Submission Info
Submission Time | |
---|---|
Task | E - Don't Be a Subsequence |
User | RFisher |
Language | C++14 (GCC 5.4.1) |
Score | 600 |
Code Size | 1227 Byte |
Status | AC |
Exec Time | 43 ms |
Memory | 22528 KB |
Compile Error
./Main.cpp: In function ‘void init()’: ./Main.cpp:40:17: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result] scanf("%s", A); ^
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 | 41 ms | 22528 KB |
11.txt | AC | 41 ms | 22528 KB |
12.txt | AC | 42 ms | 22528 KB |
13.txt | AC | 42 ms | 22528 KB |
14.txt | AC | 42 ms | 22528 KB |
15.txt | AC | 41 ms | 22528 KB |
16.txt | AC | 41 ms | 22528 KB |
17.txt | AC | 43 ms | 22528 KB |
18.txt | AC | 41 ms | 22528 KB |
19.txt | AC | 42 ms | 22528 KB |
2.txt | AC | 1 ms | 384 KB |
20.txt | AC | 42 ms | 22528 KB |
21.txt | AC | 42 ms | 22528 KB |
22.txt | AC | 43 ms | 22528 KB |
23.txt | AC | 42 ms | 22528 KB |
24.txt | AC | 43 ms | 22528 KB |
25.txt | AC | 42 ms | 22528 KB |
26.txt | AC | 42 ms | 22528 KB |
27.txt | AC | 41 ms | 22528 KB |
28.txt | AC | 42 ms | 22528 KB |
29.txt | AC | 42 ms | 22528 KB |
3.txt | AC | 3 ms | 1408 KB |
30.txt | AC | 41 ms | 22528 KB |
4.txt | AC | 3 ms | 1408 KB |
5.txt | AC | 21 ms | 13312 KB |
6.txt | AC | 21 ms | 13312 KB |
7.txt | AC | 42 ms | 22528 KB |
8.txt | AC | 43 ms | 22528 KB |
9.txt | AC | 42 ms | 22528 KB |
sample1.txt | AC | 1 ms | 256 KB |
sample2.txt | AC | 1 ms | 256 KB |
sample3.txt | AC | 1 ms | 256 KB |