QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#309408 | #8025. Fibonacci | PetroTarnavskyi# | TL | 0ms | 0kb | C++20 | 1.3kb | 2024-01-20 17:07:58 | 2024-01-20 17:07:59 |
answer
#include <bits/stdc++.h>
using namespace std;
#define FOR(i, a, b) for(int i = (a); i < (b); i++)
#define RFOR(i, a, b) for(int i = (a) - 1; i >= (b); i--)
#define SZ(a) int(a.size())
#define ALL(a) a.begin(), a.end()
#define PB push_back
#define MP make_pair
#define F first
#define S second
typedef long long LL;
typedef vector<int> VI;
typedef pair<int, int> PII;
typedef double db;
int dfs(const vector<map<string, int>>& g, VI& ignore, int v)
{
int res = 0;
for (const auto& [s, to] : g[v])
{
res += dfs(g, ignore, to);
ignore[v] &= ignore[to];
}
if (ignore[v])
{
res -= SZ(g[v]) - 1;
}
return res;
}
void solve()
{
int n, m;
cin >> n >> m;
vector<map<string, int>> g = {{}};
VI ignore = {1};
FOR(i, 0, n + m)
{
string s;
cin >> s;
s += '/';
int v = 0;
string t;
FOR(j, 0, SZ(s))
{
if (s[j] == '/')
{
if (!g[v].count(t))
{
g[v][t] = SZ(g);
g.PB({});
ignore.PB(1);
}
v = g[v][t];
}
}
ignore[v] = i < n;
}
assert(SZ(g) == SZ(ignore));
cout << dfs(g, ignore, 0) << "\n";
}
int main()
{
ios::sync_with_stdio(0);
cin.tie(0);
cout << fixed << setprecision(15);
int t;
cin >> t;
while (t--)
solve();
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 0
Time Limit Exceeded
input:
1