QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#270483#5034. >.<Galex0 7ms54168kbC++234.0kb2023-11-30 22:10:092023-11-30 22:10:10

Judging History

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

  • [2023-11-30 22:10:10]
  • 评测
  • 测评结果:0
  • 用时:7ms
  • 内存:54168kb
  • [2023-11-30 22:10:09]
  • 提交

answer

#include <bits/stdc++.h>
#define LL long long
using namespace std;

int read() {
	int s = 0, f = 1;
	char ch = getchar();
	while (ch < '0' || ch > '9')
		f = (ch == '-' ? -1 : 1), ch = getchar();
	while (ch >= '0' && ch <= '9')
		s = (s << 1) + (s << 3) + (ch ^ 48), ch = getchar();
	return s * f;
}

const int MAXN = 400005;

int n, m, k;
vector<pair<int, int> > e[MAXN];
map<pair<int, int>, int> mp, in;
int a[MAXN];

namespace SGT {
	#define N (MAXN << 5)
	#define mid ((l + r) >> 1)
	int ls[N] = {0}, rs[N] = {0}, val[N] = {0}, rt[MAXN], tot = 0;
	bool f[N] = {0};
	int copy(int x) {
		int p = ++tot;
		ls[p] = ls[x], rs[p] = rs[x];
		return p;
	}
	int mdf(int l, int r, int p, int x, int v) {
		int rt = copy(p);
		if (l == r) {
			val[rt] = v;
			return rt;
		}
		if (x <= mid)
			ls[rt] = mdf(l, mid, ls[p], x, v);
		else
			rs[rt] = mdf(mid + 1, r, rs[p], x, v);
		return rt;
	}
	void cpy(int x, int y) {
		rt[x] = rt[y];
	}
	void mdf(int t, int x, int v) {
		rt[t] = mdf(1, n, rt[t], x, v);
	}
	int qry(int l, int r, int p, int x) {
		if (!p)
			return 0;
		if (l == r)
			return val[p];
		return x <= mid ? qry(l, mid, ls[p], x) : qry(mid + 1, r, rs[p], x);
	}
	int qry(int t, int x) {
		return qry(1, n, rt[t], x);
	}
	vector<pair<int, int> > res;
	void dfs(int l, int r, int p, int x) {
		if (f[p])
			return ;
		if (l == r) {
			if (!in[make_pair(x, l)])
				return ;
			res.push_back(make_pair(l, val[p])), f[p] = 1;
			return ;
		}
		dfs(l, mid, ls[p], x), dfs(mid + 1, r, rs[p], x);
		f[p] = f[ls[p]] & f[rs[p]];
	}
	vector<pair<int, int> > go(int x, int lst) {
		res.clear(), dfs(1, n, rt[x], lst);
		return res;
	}
}

namespace AC {
	map<int, int> nxt[MAXN], val[MAXN];
	int tot = 0, fail[MAXN] = {0}, lst[MAXN] = {0};
	bool en[MAXN] = {0};
	void insert(int *a, int len) {
		for (int i = 1; i < len; i++)
			if (!in[make_pair(a[i], a[i + 1])])
				return ;
		int cur = 0;
		for (int i = 1; i <= len; i++) {
			if (!nxt[cur][a[i]])
				nxt[cur][a[i]] = ++tot, val[cur][a[i]] = i == 1 ? 0 : mp[make_pair(a[i - 1], a[i])], lst[tot] = a[i];
			cur = nxt[cur][a[i]];
		}
		en[cur] = 1;
	}
	void get_fail() {
		queue<int> q;
		for (int i = 1; i <= n; i++) {
			if (!nxt[0][i])
				nxt[0][i] = ++tot, lst[tot] = i;
			q.push(nxt[0][i]), SGT::mdf(0, i, nxt[0][i]);
		}
		while (!q.empty()) {
			int x = q.front();
			SGT::cpy(x, fail[x]), q.pop();
			for (pair<int, int> y : nxt[x])
				fail[y.second] = SGT::qry(x, y.first), q.push(y.second);
			for (pair<int, int> y : nxt[x])
				SGT::mdf(x, y.first, y.second);
		}
	}
	LL dis[MAXN];
	LL dijkstra() {
		priority_queue<pair<int, LL>, vector<pair<int, LL> >, greater<pair<int, LL> > > pq;
		memset(dis, 0x3f, sizeof dis);
		pq.push(make_pair(nxt[0][1], dis[nxt[0][1]] = 0));
		while (!pq.empty()) {
			pair<int, LL> x = pq.top();
			pq.pop();
			vector<pair<int, int> > edge = SGT::go(x.first, lst[x.first]);
			for (pair<int, int> y : edge) {
				// if (y.second == 15)
				// 	cout << x.second << endl;
				pair<int, int> tmp = make_pair(lst[x.first], y.first);
				if (!en[y.second] && in[tmp] && dis[y.second] > x.second + mp[tmp])
					pq.push(make_pair(y.second, dis[y.second] = x.second + mp[tmp]));
			}
		}
		// cout << dis[10] << endl;
		// vector<pair<int, int> > tmp = SGT::go(10);
		// for (pair<int, int> y : tmp)
		// 	cout << y.first << ' ' << y.second << endl;
		LL ans = 1e18;
		for (int i = 1; i <= tot; i++)
			if (lst[i] == n)
				ans = min(ans, dis[i]);
		return ans > 1e17 ? -1 : ans;
	}
}

signed main() {
	n = read(), m = read(), k = read();
	for (int i = 1; i <= m; i++) {
		int u = read(), v = read(), w = read();
		pair<int, int> tmp = make_pair(u, v);
		if (!in[tmp])
			mp[tmp] = 1e9, in[tmp] = 1;
		mp[tmp] = min(mp[tmp], w), e[u].push_back(make_pair(v, w));
	}
	for (int i = 1; i <= k; i++) {
		int len = read();
		for (int j = 1; j <= len; j++)
			a[j] = read();
		AC::insert(a, len);
	}
	AC::get_fail();
	printf("%lld", AC::dijkstra());
	return 0;
}

详细

Subtask #1:

score: 0
Wrong Answer

Test #1:

score: 0
Wrong Answer
time: 7ms
memory: 54168kb

input:

35 100 0
34 7 447733879
24 20 187005344
14 34 654502303
2 31 865194349
20 33 9517055
33 15 991889891
24 33 395599993
13 16 237525328
9 5 373850826
30 34 391470240
10 7 650077565
26 10 400825980
34 27 189924713
19 27 907609573
20 10 614945312
10 5 960007605
1 7 984076202
32 25 539699728
24 31 2553027...

output:

1983539809

result:

wrong answer 1st lines differ - expected: '1970522617', found: '1983539809'

Subtask #2:

score: 0
Skipped

Dependency #1:

0%

Subtask #3:

score: 0
Time Limit Exceeded

Test #11:

score: 0
Time Limit Exceeded

input:

50000 200000 1
7542 37166 116613326
3581 43961 629220971
12873 42953 440313807
31744 5286 697832848
25882 12748 106667302
34760 29676 181570340
41570 9240 885513989
22227 35688 63657981
43180 29194 174058940
8977 41899 48262624
7465 18291 600002514
46925 9281 951474878
2115 31162 373758881
5386 3798...

output:


result:


Subtask #4:

score: 0
Skipped

Dependency #2:

0%