Submission #1004908

#TimeUsernameProblemLanguageResultExecution timeMemory
1004908WhisperRima (COCI17_rima)C++17
56 / 140
251 ms168952 KiB
#include <bits/stdc++.h> using namespace std; using ll = long long; #define int long long #define FOR(i, a, b) for (int i = (a); i <= (b); i++) #define FORD(i, a, b) for (int i = (b); i >= (a); i --) #define REP(i, n) for (int i = 0; i < (n); ++i) #define REPD(i, n) for (int i = (n) - 1; i >= 0; --i) #define MASK(i) (1LL << (i)) #define BIT(x, i) (((x) >> (i)) & 1) constexpr ll LINF = (1ll << 60); constexpr int INF = (1ll << 30); constexpr int Mod = 1e9 + 7; mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); /* Phu Trong from Nguyen Tat Thanh High School for gifted student */ template <class X, class Y> bool minimize(X &x, const Y &y){ X eps = 1e-9; if (x > y + eps) {x = y; return 1;} return 0; } template <class X, class Y> bool maximize(X &x, const Y &y){ X eps = 1e-9; if (x + eps < y) {x = y; return 1;} return 0; } int n; #define MAX 3000005 #define All(x...) (x).begin(), (x).end() int dp[MAX]; struct Node{ Node* child[26]; int last, ID; Node(){ REP(i, 26) child[i] = nullptr; last = 0, ID = 0; } }; int numNode = 0; Node *root = new Node(); void Add(string &s){ Node *p = root; for (char c : s){ int nxt = (c - 'a'); if (p -> child[nxt] == nullptr){ p -> child[nxt] = new Node(); p -> child[nxt] -> ID = ++numNode; } p = p -> child[nxt]; } p -> last++; } int ans = 0; void dfs(Node *p){ REP(c, 26) if(p -> child[c] != nullptr){ dfs(p -> child[c]); } if (p -> last){ dp[p -> ID] = (p -> last); REP(c, 26) if(p -> child[c] != nullptr){ dp[p -> ID] += dp[p -> child[c] -> ID]; } maximize(ans, dp[p -> ID]); } } void process(void){ cin >> n; vector<string> s(n); for (string&i : s) cin >> i; for (string&i : s) reverse(All(i)), Add(i); dfs(root); cout << ans; } signed main(){ #define name "Whisper" cin.tie(nullptr) -> sync_with_stdio(false); // freopen(name".inp", "r", stdin); // freopen(name".out", "w", stdout); process(); }
#Verdict Execution timeMemoryGrader output
Fetching results...