# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
242132 | ant101 | Rima (COCI17_rima) | C++14 | 5 ms | 384 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <cstdio>
#include <cstring>
#include <cassert>
#include <algorithm>
#include <iostream>
#include <vector>
#include <fstream>
using namespace std;
#define TRACE(x) cerr << #x << " = " << x << endl
#define REP(i, n) for (int i=0; i<n; i++)
#define FOR(i, a, b) for (int i=(a); i<(b); i++)
typedef long long ll;
typedef pair<int, int> P;
#define X first
#define Y second
const int MAX = 3000100;
struct node {
int br, dp;
vector <pair<char, node*> > V;
node() {
br = dp = 0;
V.clear();
}
} *root;
char s[MAX];
int rje = 0;
void insert()
{
int len = (int) strlen(s);
node *tmp = root;
REP(i, len) {
node *nov = 0;
for (auto it : tmp->V)
if (it.X == s[i]) {
nov = it.Y;
break;
}
if (!nov) {
nov = new node;
tmp->V.push_back({s[i], nov});
}
tmp = nov;
}
tmp->br = 1;
}
void dfs(node *p)
{
P mx{0, 0};
int ima = 0;
for (auto it : p->V) {
dfs(it.Y);
ima += it.Y->br;
mx = max(mx, P(mx.X, it.Y->dp));
mx = max(mx, P(it.Y->dp, mx.X));
p->dp = max(p->dp, it.Y->dp);
}
if (p->br) p->dp += 1 + max(0, ima-1);
else p->dp = 0;
rje = max(rje, mx.X + mx.Y + p->br + max(0, ima - 2));
}
int main()
{
root = new node;
ifstream in;
ifstream ino;
in.open("rima.in.6");
ino.open("rima.out.6");
int sol;
ino >> sol;
ino.close();
int n;
in >> n;
REP(i, n) {
in >> s;
reverse(s, s + strlen(s));
insert();
}
in.close();
dfs(root);
cout << rje << endl;
cout << sol << endl;
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |