이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <iostream>
#include <vector>
#include <stdio.h>
#include <algorithm>
#include <map>
#include <fstream>
#include <set>
#include <cstring>
#include <cassert>
#include <cstdlib>
#include <cmath>
#include <queue>
#define N 2000000
using namespace std;
typedef long long ll;
const ll INF = 1e15, MOD = 1e9 + 7, MOD2 = 1e6 + 3;
struct Trie {
struct Node {
int d;
map < pair <char, char>, Node* > to;
bool leaf;
Node () : d (0), leaf (false) {}
};
Node* root = new Node ();
int add (string s) {
string t = s;
reverse (t.begin(), t.end());
int d = 1;
Node* x = root;
for (int i = 0; i < s.length (); i++) {
if (x -> to.find ({s[i], t[i]}) == x -> to.end ()) {
x -> to[{s[i], t[i]}] = new Node ();
}
x = x -> to[{s[i], t[i]}];
if (x -> leaf) d = max (d, x -> d + 1);
}
x -> leaf = true;
x -> d = d;
return d;
}
} t;
bool comp (const string& a, const string& b) {
return a.length () < b.length ();
}
int n;
string s[N];
int main () {
cin >> n;
for (int i = 0; i < n; i++) {
cin >> s[i];
}
sort (s, s + n, comp);
int ans = 0;
for (int i = 0; i < n; i++) {
ans = max (ans, t.add (s[i]));
}
cout << ans;
}
컴파일 시 표준 에러 (stderr) 메시지
savez.cpp: In member function 'int Trie::add(std::__cxx11::string)':
savez.cpp:40:21: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for (int i = 0; i < s.length (); i++) {
~~^~~~~~~~~~~~~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |