?
# | Author | Problem | Lang | Verdict | Time | Memory | Sent | Judged | |
---|---|---|---|---|---|---|---|---|---|
77282904 |
Practice: jajantaram |
1321C - 19 | C++17 (GCC 7-32) | Time limit exceeded on test 9 | 2000 ms | 77288 KB | 2020-04-19 17:12:44 | 2020-04-19 17:12:44 |
#include<bits/stdc++.h> using namespace std; int n; unordered_map<string,int>dp; bool isvalid(int pos,int size) { if(pos<0||pos>=size) return false; return true; } int rec(string s) { if(s.size()==0) return 0; if(dp[s]!=0) return dp[s]; int i,m=0; for(i=0;i<s.size();i++) { if((isvalid(i-1,s.size())&&s[i]-s[i-1]==1)||(isvalid(i+1,s.size())&&s[i]-s[i+1]==1)) { string a=s; a.erase(a.begin()+i); m=max(m,1+rec(a)); } } return dp[s]=m; } int main() { cin>>n; string s; cin>>s; cout<<rec(s); }
?
?
?
?