Submission #2531939
Source Code Expand
/* --- author: dxm --- */ #include<bits/stdc++.h> using namespace std; #define INF 1e9 #define Inf 1e18 #define rep(i,n) for(int (i)=0;(i)<n;i++) #define REP(i,n) for(int (i)=1;(i)<=n;i++) #define mp make_pair #define pb push_back #define pii pair<int,int> #define fst first #define snd second typedef long long ll; inline void Fail(){printf("0");exit(0);} const int maxn=200005; const int maxm=30; int n; char c[maxn]; string s,ans; int nxt[maxn][maxm],dp[maxn]; int main(){ scanf("%s",c);s=c;n=s.size();s="*"+s; rep(j,26)nxt[n+1][j]=n+1; for(int i=n;i>=1;i--)rep(j,26){ if(s[i]-'a'==j)nxt[i][j]=i; else nxt[i][j]=nxt[i+1][j]; } dp[n+1]=0; for(int i=n;i>=0;i--){ dp[i]=INF; rep(j,26)dp[i]=min(dp[i],dp[nxt[i+1][j]]+1); // cout<<dp[i]<<endl; } // printf("%d\n",dp[0]); int cur=0,now=0; while(cur<n){ now++; rep(i,26){ if(now+dp[nxt[cur+1][i]]==dp[0]){ cur=nxt[cur+1][i]; ans+=(char)(i+'a'); break; } } } printf("%s",ans.c_str()); return 0; } /* Input: ----------------- Output: */
Submission Info
Submission Time | |
---|---|
Task | E - Don't Be a Subsequence |
User | little_waxberry |
Language | C++ (GCC 5.4.1) |
Score | 600 |
Code Size | 1087 Byte |
Status | AC |
Exec Time | 25 ms |
Memory | 24892 KB |
Compile Error
./Main.cpp: In function ‘int main()’: ./Main.cpp:25:15: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result] scanf("%s",c);s=c;n=s.size();s="*"+s; ^
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 | 25 ms | 24892 KB |
11.txt | AC | 24 ms | 24892 KB |
12.txt | AC | 25 ms | 24764 KB |
13.txt | AC | 24 ms | 24892 KB |
14.txt | AC | 24 ms | 24892 KB |
15.txt | AC | 24 ms | 24892 KB |
16.txt | AC | 24 ms | 24892 KB |
17.txt | AC | 24 ms | 24892 KB |
18.txt | AC | 24 ms | 24892 KB |
19.txt | AC | 24 ms | 24892 KB |
2.txt | AC | 1 ms | 384 KB |
20.txt | AC | 24 ms | 24892 KB |
21.txt | AC | 24 ms | 24892 KB |
22.txt | AC | 24 ms | 24892 KB |
23.txt | AC | 24 ms | 24892 KB |
24.txt | AC | 24 ms | 24892 KB |
25.txt | AC | 24 ms | 24892 KB |
26.txt | AC | 24 ms | 24892 KB |
27.txt | AC | 24 ms | 24892 KB |
28.txt | AC | 24 ms | 24892 KB |
29.txt | AC | 24 ms | 24892 KB |
3.txt | AC | 3 ms | 1536 KB |
30.txt | AC | 24 ms | 24892 KB |
4.txt | AC | 3 ms | 1536 KB |
5.txt | AC | 13 ms | 14464 KB |
6.txt | AC | 13 ms | 14464 KB |
7.txt | AC | 24 ms | 24892 KB |
8.txt | AC | 24 ms | 24892 KB |
9.txt | AC | 24 ms | 24892 KB |
sample1.txt | AC | 1 ms | 256 KB |
sample2.txt | AC | 1 ms | 256 KB |
sample3.txt | AC | 1 ms | 256 KB |