Submission #994043

# Submission time Handle Problem Language Result Execution time Memory
994043 2024-06-07T05:02:02 Z vjudge1 Rima (COCI17_rima) C++17
56 / 140
276 ms 137384 KB
#include<bits/stdc++.h>

using namespace std;

struct node
{
  node * ch[26] = {NULL};
  bool e = false;
  int dp;

  int dfs()
  {
    // cerr << "I'm" << endl;
    int ans = 0;
    int mx = 0;
    dp = e;
    for(int i = 0; i < 26; i++)
      {
	if(ch[i] == NULL) continue;

	// cerr << "---> " << char(i + 'a') << endl;
	ans = max(ans, ch[i]->dfs());
	// cerr << ch[i] -> dp << endl;
	// cerr << "<---" << char(i + 'a') << endl;
	if(ch[i] -> e)
	  {
	    mx = max(mx, ch[i]->dp - 1);
	    dp++;
	  }
      }
    
    dp += mx;
    ans = max(ans, dp);
    return ans;
  }
};

struct Trie
{
  node * root;
  Trie() {
    root = new node();
  }

  void insert(string &s)
  {
    node *cur = root;
    for(int i = s.size() - 1; i >= 0; i--)
      {
	int idx = s[i] - 'a';
	if(cur -> ch[idx] == NULL)
	  cur -> ch[idx] = new node();
	cur = cur -> ch[idx];
      }
    cur -> e = true;
  }

  int compute()
  {
    return root->dfs();
  }
  
} T;

int main()
{
  int n;
  cin >> n;
  for(int i = 0; i < n; i ++)
    {
      string s;
      cin >> s;
      T.insert(s);
    }
  cout << T.compute() << endl;
  return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 600 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Incorrect 276 ms 137384 KB Output isn't correct
5 Correct 43 ms 3664 KB Output is correct
6 Incorrect 69 ms 77876 KB Output isn't correct
7 Incorrect 71 ms 77608 KB Output isn't correct
8 Incorrect 63 ms 77256 KB Output isn't correct
9 Incorrect 117 ms 83096 KB Output isn't correct
10 Incorrect 63 ms 77336 KB Output isn't correct