답안 #583863

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
583863 2022-06-26T10:41:42 Z MilosMilutinovic Rima (COCI17_rima) C++14
28 / 140
447 ms 102788 KB
/**
 *    author:  wxhtzdy
 *    created: 26.06.2022 12:34:37
**/
#include <bits/stdc++.h>

using namespace std;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);  
  int n;
  cin >> n;
  vector<string> s(n);
  for (int i = 0; i < n; i++) {
    cin >> s[i];
    reverse(s[i].begin(), s[i].end());
  }
  sort(s.begin(), s.end(), [&](string a, string b) {
    if (a.size() != b.size()) {
      return a.size() < b.size();
    } else {
      return a < b;
    }
  });
  vector<vector<int>> trie(1, vector<int>(26, -1));
  vector<int> dp(1, 0);
  for (int i = 0; i < n; i++) {
    int p = 0, f = 0;
    int mx = 0;
    int sz = (int) s[i].size();
    if (sz == 1) {
      mx = dp[0];
    }
    for (int j = 0; j < sz; j++) {
      int c = (int) (s[i][j] - 'a');
      if (trie[p][c] == -1) {
        trie[p][c] = (int) trie.size();
        trie.push_back(vector<int>(26, -1));
        dp.push_back(0);        
      }
      p = trie[p][c];
      if (j == sz - 2) {           
        f = p;
      }
      if (j + 2 >= sz) {
        mx = max(mx, dp[p]);
      }
    }
    dp[f] = max(dp[f], mx + 1);
    dp[p] = max(dp[p], mx + 1);
  }          
  cout << *max_element(dp.begin(), dp.end()) << '\n';
  return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 340 KB Output isn't correct
2 Correct 1 ms 340 KB Output is correct
3 Incorrect 1 ms 340 KB Output isn't correct
4 Incorrect 447 ms 102788 KB Output isn't correct
5 Correct 31 ms 6540 KB Output is correct
6 Incorrect 47 ms 43720 KB Output isn't correct
7 Incorrect 39 ms 43472 KB Output isn't correct
8 Incorrect 36 ms 43244 KB Output isn't correct
9 Incorrect 87 ms 50152 KB Output isn't correct
10 Incorrect 37 ms 43288 KB Output isn't correct