QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#322849#1193. Ambiguous EncodingcomplexorWA 1ms3928kbC++232.5kb2024-02-07 21:13:212024-02-07 21:13:22

Judging History

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

  • [2024-02-07 21:13:22]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:3928kb
  • [2024-02-07 21:13:21]
  • 提交

answer

#include <bits/stdc++.h>
#define clr(f, n) memset(f, 0, (n) << 2)
#define cpy(f, g, n) memcpy(f, g, (n) << 2)
typedef long long LL;
typedef unsigned long long ULL;
typedef __int128 LLL;
typedef std::pair<int, int> pii;
#define MP std::make_pair
#define fi first
#define se second
int read()
{
	int s = 0, f = 1;
	char c = getchar();
	while (!(c >= '0' && c <= '9'))
		f ^= (c == '-'), c = getchar();
	while (c >= '0' && c <= '9')
		s = s * 10 + (c ^ 48), c = getchar();
	return f ? s : -s;
}
const int MAXN = 1005, MAXW = 20, inf = 0x3f3f3f3f;
int n, N = 0, dis[MAXN][MAXW];
std::vector<int> a[MAXN];
std::string str;
int ch[MAXN * MAXW][2], tot = 1;
std::vector<int> rec[MAXN * MAXW], end[MAXN * MAXW];
struct Node
{
	int i, j, w;
	Node(){}
	Node(int _i, int _j, int _w)
	: i(_i), j(_j), w(_w) {}
	friend bool operator<(Node a, Node b){ return a.w > b.w; }
};
std::vector<Node> e[MAXN][MAXW];
void Dijkstra()
{
	static std::priority_queue<Node> q;
	static bool vis[MAXN][MAXW];
	memset(vis, false, sizeof vis);
	memset(dis, inf, sizeof dis);
	for (int i = 1; i <= n; i++)
		q.emplace(i, a[i].size(), dis[i][a[i].size()] = 0);
	while (!q.empty())
	{
		Node x = q.top(); q.pop();
		if (vis[x.i][x.j]) continue;
		vis[x.i][x.j] = true;
		for (Node y : e[x.i][x.j])
			if (dis[y.i][y.j] > x.w + y.w)
				q.emplace(y.i, y.j, dis[y.i][y.j] = y.w + x.w);
	}
}
int main()
{
	n = read();
	for (int i = 1; i <= n; i++)
	{
		std::cin >> str;
		for (char c : str) a[i].push_back(c - '0');
		int x = 1;
		for (int j = 0; j < a[i].size(); x = ch[x][a[i][j++]])
			if (!ch[x][a[i][j]]) ch[x][a[i][j]] = ++tot;
		end[x].push_back(i);
	}
	for (int i = tot; i; i--)
	{
		rec[i] = end[i];
		for (int c = 0; c <= 1; c++)
			if (ch[i][c])
				for (int x : rec[ch[i][c]])
					rec[i].push_back(x);
	}
	for (int i = 1; i <= n; i++)
		for (int j = 1; j <= a[i].size(); j++)
		{
			int x = 1;
			for (int k = (int)a[i].size() - j; k < a[i].size(); k++)
			{
				x = ch[x][a[i][k]];
				for (int y : end[x])
					if (j < a[i].size() || y != i)
						e[i][j].emplace_back(i, j - a[y].size(), a[y].size());
			}
			if (x)
				for (int y : rec[x])
					if (j <= a[y].size()) e[i][j].emplace_back(y, a[y].size() - j, j);
			// printf("%d %d:\n", i, j);
			// for (Node y : e[i][j]) printf("%d %d %d\n", y.i, y.j, y.w);
		}
	Dijkstra();
	int ans = inf;
	for (int i = 1; i <= n; i++)
		ans = std::min(ans, dis[i][0]);
	printf("%d\n", ans < inf ? ans : 0);
	return 0;
}

詳細信息

Test #1:

score: 0
Wrong Answer
time: 1ms
memory: 3928kb

input:

3
0
01
10

output:

1

result:

wrong answer expected '3', found '1'