QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#322846#1193. Ambiguous EncodingcomplexorWA 1ms4240kbC++232.5kb2024-02-07 21:06:392024-02-07 21:06:39

Judging History

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

  • [2024-02-07 21:06:39]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:4240kb
  • [2024-02-07 21:06:39]
  • 提交

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 = 16, 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: 100
Accepted
time: 1ms
memory: 3900kb

input:

3
0
01
10

output:

3

result:

ok answer is '3'

Test #2:

score: 0
Accepted
time: 1ms
memory: 3948kb

input:

3
00
01
1

output:

0

result:

ok answer is '0'

Test #3:

score: 0
Accepted
time: 1ms
memory: 3944kb

input:

3
00
10
1

output:

0

result:

ok answer is '0'

Test #4:

score: 0
Accepted
time: 1ms
memory: 3948kb

input:

10
1001
1011
01000
00011
01011
1010
00100
10011
11110
0110

output:

13

result:

ok answer is '13'

Test #5:

score: 0
Accepted
time: 1ms
memory: 3944kb

input:

3
1101
1
10

output:

4

result:

ok answer is '4'

Test #6:

score: -100
Wrong Answer
time: 1ms
memory: 4240kb

input:

100
1010011110001
00000100010101
011010100100001
11100001100011
10010001010
1110001110110011
01001100111
1010100110010100
00000100111010
100111001100101
0010000000010
0111110011100110
0100111000001
1100101111110001
1100100110001
10100011010
10100000011000
1111001111001110
000000000101011
10101111011...

output:

0

result:

wrong answer expected '102', found '0'