QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#309408#8025. FibonacciPetroTarnavskyi#TL 0ms0kbC++201.3kb2024-01-20 17:07:582024-01-20 17:07:59

Judging History

你现在查看的是最新测评结果

  • [2024-01-20 17:07:59]
  • 评测
  • 测评结果:TL
  • 用时:0ms
  • 内存:0kb
  • [2024-01-20 17:07:58]
  • 提交

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;
}

詳細信息

Test #1:

score: 0
Time Limit Exceeded

input:

1

output:


result: