# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
229894 | mohamedsobhi777 | Rima (COCI17_rima) | C++14 | 815 ms | 10072 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include<bits/stdc++.h>
using namespace std ;
const int N = 1e5 + 7 ;
int n ;
int dp[N] ;
int ans ;
string ss[N] ;
bool katch(int i , int j){
if( abs( (int) ss[i].size() - (int) ss[j].size()) > 1 ) return 0 ;
string s1 = ss[i] .substr(0 , ss[j].size() -1 ) ;
string s2 = ss[j] .substr(0 , ss[j].size()-1) ;
return (s1 == s2) ;
}
bool match(int i , int j){
return katch(i , j ) ;
}
int main(){
ios_base::sync_with_stdio(0) ;
cin.tie(0) ;
cin>>n ;
for(int i = 0 ; i < n ;i++){
cin>>ss[i] ;
reverse( ss[i] .begin() , ss[i].end()) ;
}
sort(ss , ss + n) ;
for(int i = 0 ;i < n ;i++){
dp[i] = 1 ;
for(int j = 0 ; j < i ; j++){
if(match(j , i)){
dp[i] = max(dp[i] , dp[j]+1) ;
}
}
ans = max(ans , dp[i]) ;
}
cout<< ans ;
return 0 ;
}
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |