QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#663297#4852. RestoranizxyTL 6ms31420kbC++143.2kb2024-10-21 14:44:032024-10-21 14:44:03

Judging History

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

  • [2024-10-21 14:44:03]
  • 评测
  • 测评结果:TL
  • 用时:6ms
  • 内存:31420kb
  • [2024-10-21 14:44:03]
  • 提交

answer

//  ______                                                 _  __
// |  ____|                                          /\   | |/ /
// | |____   _____ _ __ _   _  ___  _ __   ___      /  \  | ' /    ______  ___   _
// |  __\ \ / / _ \ '__| | | |/ _ \| '_ \ / _ \    / /\ \ |  <    |_  /\ \/ / | | |
// | |___\ V /  __/ |  | |_| | (_) | | | |  __/   / ____ \| . \    / /  >  <| |_| |
// |______\_/ \___|_|   \__, |\___/|_| |_|\___|  /_/    \_\_|\_\  /___|/_/\_\\__, |
//                       __/ |                                                __/ |
//                      |___/                                                |___/
#include <bits/stdc++.h>
#define int long long
using namespace std;
mt19937 rnd(time(0) ^ clock());
const int N = 1e6 + 147, M = 1e3 + 147,  mod = 998244353, INF = 1e18;
int n, head[M], ver[N * 2], Next[N * 2], tot;
int low[N], dfn[N], tim, st[N], top, cnt, ins[N], bel[N], xx[M], yy[M], minn[M][M], f[M][M], res[M];
vector<int> t[M], G[M];
int random(int l, int r) {
	return rnd() % (r - l + 1) + l;
}
int read() {
	char ch;
	int s = 0; int w = 1;
	while ((ch = getchar()) > '9' || ch < '0') if (ch == '-') w = -1;
	while (ch >= '0' && ch <= '9') s = (s << 1) + (s << 3) + (ch ^ 48), ch = getchar();
	return s * w;
}
void add(int x, int y) {
	ver[++tot] = y;
	Next[tot] = head[x];
	head[x] = tot;
}
void tarjan(int x) {
	low[x] = dfn[x] = ++tim;
	st[++top] = x;
	ins[x] = 1;
	for (int i = head[x]; i; i = Next[i]) {
		int y = ver[i];
		if (!dfn[y]) {
			tarjan(y);
			low[x] = min(low[x], low[y]);
		}
		else if (ins[y]) low[x] = min(low[x], dfn[y]);
	}
	if (dfn[x] == low[x]) {
		cnt++;
		int y;
		do {
			y = st[top--];
			ins[y] = 0;
			bel[y] = cnt;
			t[cnt].push_back(y);
		} while (x != y);
	}
}
bool cmp(int a, int b) {
	if (xx[a] == xx[b]) return yy[a] < yy[b];
	return xx[a] < xx[b];
}
void dfs(int x, int fa) {
	for (int i = n; i >= 0; i--) {
		for (int j = min(i, (int)t[x].size()); j >= 0; j--) {
			f[x][i] = min(f[x][i], f[fa][i - j] + minn[x][j]);
			res[i] = min(res[i], f[x][i]);
		}
	}
	for (int i = 0; i < (int)G[x].size(); i++) {
		int y = G[x][i];
		dfs(y, x);
	}
}
signed main() {
	n = read();
	for (int i = 1; i <= n; i++) {
		xx[i] = read(); yy[i] = read();
		int tmp = read();
		while (tmp--) {
			int j = read();
			add(i, j);
		}
	}
	for (int i = 1; i <= n; i++) if (!dfn[i]) tarjan(i);
	memset(minn, 0x3f, sizeof(minn));
	for (int i = 1; i <= cnt; i++) {
		sort(t[i].begin(), t[i].end(), cmp);
		minn[i][0] = 0;
		for (int j = 0; j < (int)t[i].size(); j++) {
			int sum = 0;
			minn[i][1] = min(minn[i][1], yy[t[i][j]]);
			for (int k = 0; k < (int)t[i].size(); k++) {
				if (j != k) sum += xx[t[i][k]];
				minn[i][k + 1 + (j > k)] = min(minn[i][k + 1 + (j > k)], sum + yy[t[i][j]]);
			}
		}
	}
	for (int x = 1; x <= n; x++) {
		for (int i = head[x]; i; i = Next[i]) {
			int u = bel[x], v = bel[ver[i]];
			if (u == v) continue;
			G[u].push_back(v);
		}
	}
	memset(res, 0x3f, sizeof(res));
	for (int i = 1; i <= cnt; i++) {
		memset(f, 0x3f, sizeof(f));
		f[0][0] = 0;
		dfs(i, 0);
	}
	for (int i = 1; i <= n; i++) {
		if (res[i] <= 1e15) printf("%lld\n", res[i]);
		else break;
	}
	return 0;
}

詳細信息

Test #1:

score: 100
Accepted
time: 6ms
memory: 31420kb

input:

1000
2856 4225 9 773 772 383 359 750 327 752 465 612
5478 5990 6 452 449 938 60 930 374
2088 2765 3 703 416 845
8905 1853 3 891 518 651
8249 9640 5 844 126 767 602 549
8956 9158 5 321 126 633 228 147
115 559 10 996 649 568 530 473 268 457 746 815 758
7208 9975 8 164 365 391 481 821 587 964 118
2260 ...

output:

56
57
63
85
107
131
155
180
207
237
270
305
340
380
426
473
536
618
704
794
885
977
1076
1186
1297
1409
1524
1640
1759
1882
2005
2130
2257
2398
2543
2688
2838
2994
3152
3319
3490
3665
3840
4027
4216
4405
4614
4824
5036
5249
5462
5682
5903
6139
6379
6622
6867
7114
7368
7626
7893
8162
8434
8709
8985
9...

result:

ok 1000 lines

Test #2:

score: -100
Time Limit Exceeded

input:

1000
4409 7088 4 774 678 552 582
600 7071 4 386 128 135 393
154 205 5 508 106 866 374 384
390 5420 9 881 365 543 784 801 730 413 177 200
2470 3366 3 314 905 772
5563 9537 4 372 357 628 691
5281 6770 2 595 761
3436 9375 3 641 338 668
2113 2528 1 742
3114 8123 6 479 145 736 802 354 764
304 2375 2 529 ...

output:


result: