Submission #229894

# Submission time Handle Problem Language Result Execution time Memory
229894 2020-05-07T04:59:31 Z mohamedsobhi777 Rima (COCI17_rima) C++14
28 / 140
815 ms 10072 KB
#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
1 Incorrect 6 ms 3456 KB Output isn't correct
2 Correct 7 ms 3456 KB Output is correct
3 Incorrect 6 ms 3456 KB Output isn't correct
4 Runtime error 19 ms 7680 KB Execution killed with signal 11 (could be triggered by violating memory limits)
5 Correct 28 ms 9344 KB Output is correct
6 Incorrect 29 ms 4760 KB Output isn't correct
7 Incorrect 20 ms 4516 KB Output isn't correct
8 Incorrect 15 ms 4444 KB Output isn't correct
9 Incorrect 815 ms 10072 KB Output isn't correct
10 Incorrect 14 ms 4548 KB Output isn't correct