QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#189784#4899. 机器orz_z100 ✓415ms42940kbC++145.0kb2023-09-27 21:35:412023-09-27 21:35:43

Judging History

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

  • [2023-09-27 21:35:43]
  • 评测
  • 测评结果:100
  • 用时:415ms
  • 内存:42940kb
  • [2023-09-27 21:35:41]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
//#define int long long
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef double db;
#define F(i, a, b) for(int i = a; i <= (b); ++i)
#define F2(i, a, b) for(int i = a; i < (b); ++i)
#define dF(i, a, b) for(int i = a; i >= (b); --i)
template<typename T> void debug(string s, T x) {cerr << "[" << s << "] = [" << x << "]\n";}
template<typename T, typename... Args> void debug(string s, T x, Args... args) {for (int i = 0, b = 0; i < (int)s.size(); i++) if (s[i] == '(' || s[i] == '{') b++;else if (s[i] == ')' || s[i] == '}') b--;else if (s[i] == ',' && b == 0) {cerr << "[" << s.substr(0, i) << "] = [" << x << "] | ";debug(s.substr(s.find_first_not_of(' ', i + 1)), args...);break;}}
#ifdef ONLINE_JUDGE
#define Debug(...)
#else
#define Debug(...) debug(#__VA_ARGS__, __VA_ARGS__)
#endif
#define pb push_back
#define fi first
#define se second
#define Mry fprintf(stderr, "%.3lf MB\n", (&Med - &Mbe) / 1048576.0)
#define Try cerr << 1e3 * clock() / CLOCKS_PER_SEC << " ms\n";
typedef long long ll;
// namespace Fread {const int SIZE = 1 << 17; char buf[SIZE], *S, *T; inline char getchar() {if (S == T) {T = (S = buf) + fread(buf, 1, SIZE, stdin); if (S == T) return '\n';} return *S++;}}
// namespace Fwrite {const int SIZE = 1 << 17; char buf[SIZE], *S = buf, *T = buf + SIZE; inline void flush() {fwrite(buf, 1, S - buf, stdout), S = buf;} inline void putchar(char c) {*S++ = c;if (S == T) flush();} struct NTR {~NTR() {flush();}} ztr;}
// #ifdef ONLINE_JUDGE
// #define getchar Fread::getchar
// #define putchar Fwrite::putchar
// #endif
inline int ri() {
	int x = 0;
	bool t = 0;
	char c = getchar();
	while (c < '0' || c > '9') t |= c == '-', c = getchar();
	while (c >= '0' && c <= '9') x = (x << 3) + (x << 1) + (c ^ 48), c = getchar();
	return t ? -x : x;
}
inline void wi(int x) {
	if (x < 0) {
		putchar('-'), x = -x;
	}
	if (x > 9) wi(x / 10);
	putchar(x % 10 + 48);
}
inline void wi(int x, char s) {
	wi(x), putchar(s);
}
bool Mbe;
const int mod = 998244353;
const int inf = 0x3f3f3f3f;
const ll infll = 1e18;
const int _ = 2000 + 5;
vi d[_];
int p[_], q[_], a[_][_], b[_][_], h[_];
bool vis[_];
//template<int _, int 1000000>;
struct MCMF {
	int nn, s, t, tot = 1, cur[_], head[_], to[1000000  + 5], nxt[1000000 + 5];
	ll fl[1000000 + 6];
//	void init() {
//		nn = 0, tot = 1;
//	}
	void add(int u, int v, ll w) {
//		cout << " !!! " << u << " " <<v <<" " << w << '\n';
		to[++tot] = v, nxt[tot] = head[u], fl[tot] = w, head[u] = tot;
	}
	void Add(int u, int v, ll w) {
		add(u, v, w), add(v, u, 0);
	}
	int ds[_];
	bool bfs() {
		F(i, 1, t) ds[i] = 0;
		ds[s] = 1;
		queue<int> q;
		q.push(s);
//		memcpy(cur, head, sizeof(int) * (nn + 3));
		while(!q.empty()) {
			int u = q.front();
			q.pop();
			for(int i = head[u], v = to[i]; i; i = nxt[i], v = to[i]) if(!ds[v] && fl[i] > 0) {
				ds[v] = ds[u] + 1, q.push(v);
			}
		}
		return ds[t];
	}
	ll dfs(int x, ll in) {
		if(x == t) return in;
		ll out = 0;
		for(int &i = cur[x]; i && in; i = nxt[i]) if(fl[i] > 0 && ds[to[i]] == ds[x] + 1) {
			ll p = dfs(to[i], min(in, fl[i]));
			fl[i] -= p, fl[i ^ 1] += p;
			in -= p, out += p;
		}
		return out;
	}
	void oo(int x) {
		vis[x] = 1;
		for(int i = head[x]; i; i = nxt[i]) if(fl[i] > 0 && !vis[to[i]]) oo(to[i]);
	}
} G;
int n, m, pk[_];
ll vw[_];
int ans[_];
//MCMF<2005, 1000005> G;

ll Fg(int u, int x) {
	ll s = 0;
	F(i, 1, p[u]) s += max(0, -x + h[u] - a[u][i]);
	F(i, 1, q[u]) s += max(0, x - h[u] - b[u][i]);
	return s;
}
void solve(vi g, int l, int r) {
//	for(int v : g) cout << v << ' ';
//	cout << " ( " << l << " " << r << " ) \n";
	if(g.empty()) return;
	if(l == r) {
		for(int v : g) ans[v] = l;
		return;
	}
	int mid = (l + r) >> 1;
	F(i, 1, G.nn) G.head[i] = G.cur[i] = vis[i] = 0;
	G.nn = 0, G.tot = 1;
	for(int v : g) pk[v] = ++G.nn;
	G.s = ++G.nn, G.t = ++G.nn;
	F(i, 1, G.nn) G.head[i] = G.cur[i] = vis[i] = 0;
	for(int i : g) {
		vw[i] = Fg(i, mid + 1) - Fg(i, mid);
//		cout << vw[i] << "!!\n";
		if(vw[i] > 0) G.Add(G.s, pk[i], vw[i]);
		else G.Add(pk[i], G.t, -vw[i]);
	}
	for(int a : g) for(int b : d[a]) if(pk[b]) G.Add(pk[b], pk[a], infll);
//	Debug(G.tot);
	while(G.bfs()) {
		F(i, 1, G.nn) G.cur[i] = G.head[i];
		G.dfs(G.s, infll);
	}
	G.oo(G.s);
//	F(i, 1, n) cout << vis[i] << " ";
//	cout << " fuck\n";
	vi t1, t2;
	for(int v : g) if(vis[pk[v]]) t1.pb(v); else t2.pb(v);
	for(int v : g) pk[v] = 0;
	solve(t1, l, mid), solve(t2, mid + 1, r);
}
bool Med;
signed main() {
	// Mry;
	n = ri(), m = ri();
	F(i, 1, n) h[i] = ri();
	F(i, 1, m) {
		int u = ri(), v = ri();
		d[u].pb(v);
	}
	F(i, 1, n) {
		p[i] = ri();
		F(j, 1, p[i]) a[i][j] = ri();
	}
	F(i, 1, n) {
		q[i] = ri();
		F(j, 1, q[i]) b[i][j] = ri();
	}
	vi g;
	F(i, 1, n) g.pb(i);
	solve(g, -2e8, 2e8);
	ll Ans = 0;
	F(i, 1, n) Ans += Fg(i, ans[i]);
//	F(i, 1, n) cout << ans[i] <<' ';
//	cout << '\n';
	printf("%lld\n", Ans);
	// Try;
	return 0;
}

詳細信息

Test #1:

score: 4
Accepted
time: 0ms
memory: 11920kb

input:

50 200
18 6 25 0 25 13 15 11 28 3 20 1 28 7 17 29 9 21 8 16 19 20 7 13 13 7 3 6 10 16 15 28 14 10 20 1 16 5 4 14 0 24 15 21 24 25 20 25 8 28
42 28
11 1
38 24
30 22
28 6
19 50
27 16
31 47
29 9
15 24
18 40
2 8
31 32
1 43
32 38
32 8
11 31
41 38
31 8
10 24
41 42
22 21
21 35
25 40
24 29
47 6
50 48
37 29
...

output:

1936

result:

ok 1 number(s): "1936"

Test #2:

score: 4
Accepted
time: 0ms
memory: 12000kb

input:

50 200
12 17 27 19 16 26 9 12 13 26 21 21 17 9 5 0 2 8 16 19 3 17 13 19 12 1 16 9 7 2 8 12 11 27 1 19 15 2 2 28 28 15 11 7 24 8 0 26 16 16
18 33
45 3
49 15
8 4
48 16
27 49
36 23
50 13
45 7
50 15
8 32
50 28
46 30
45 46
48 4
44 2
42 28
29 2
28 17
22 23
3 21
37 4
20 6
35 1
43 47
33 43
1 34
36 2
27 31
1...

output:

1727

result:

ok 1 number(s): "1727"

Test #3:

score: 4
Accepted
time: 0ms
memory: 14032kb

input:

70 148
648 907 1017 1228 1372 708 532 3 1054 303 1488 1536 768 1812 1034 1965 1990 675 441 1821 1291 67 365 283 1754 76 1046 238 1585 173 1837 585 1080 1207 1813 804 267 697 807 1322 1000 295 1210 120 459 244 437 801 1272 879 623 563 1298 1340 846 1052 1769 245 1643 1354 418 1480 291 1850 1039 104 6...

output:

2646563

result:

ok 1 number(s): "2646563"

Test #4:

score: 4
Accepted
time: 3ms
memory: 11988kb

input:

70 178
311 290 331 1728 1193 1766 762 698 1658 1086 1760 1437 1698 949 959 154 1905 174 601 928 1257 380 1249 896 110 606 1053 702 36 135 480 347 777 1163 76 1970 1281 838 668 939 1925 781 728 1975 1730 1687 481 1987 1861 1434 1267 1470 167 517 718 277 1475 1772 979 1511 259 1811 1859 1388 974 287 1...

output:

3047983

result:

ok 1 number(s): "3047983"

Test #5:

score: 4
Accepted
time: 0ms
memory: 14056kb

input:

100 211
7523 7559 4047 9618 1325 7742 9742 3270 8367 5811 4033 2453 6391 4333 4009 1094 4351 198 3941 5230 8697 1805 9214 5042 8815 2396 6846 6052 1834 27 5114 9357 3938 9161 5328 5263 3255 5070 4886 1622 7234 8919 4075 3625 9604 4437 1071 3955 4635 1365 9185 3333 3170 4751 8375 8338 3499 1573 4390 ...

output:

35670136

result:

ok 1 number(s): "35670136"

Test #6:

score: 4
Accepted
time: 0ms
memory: 14008kb

input:

100 180
9338 5120 5309 9660 7124 5799 6588 3943 6227 8670 5407 1360 2486 7959 2074 8547 7272 9318 2800 3390 7456 6641 4697 6002 6282 3789 2206 4536 3203 9231 3215 2541 703 4876 8553 4180 7028 5141 8123 3255 3811 3530 4615 6297 7842 3041 1197 1466 2360 3997 1208 6168 6991 2257 2171 9625 6047 729 4161...

output:

34980971

result:

ok 1 number(s): "34980971"

Test #7:

score: 4
Accepted
time: 0ms
memory: 11940kb

input:

100 314
2431 3032 1166 8304 6258 5339 6169 7414 4008 5426 5943 7867 9137 455 8700 4076 667 2076 589 5564 6219 308 2784 8673 8785 2322 8077 2669 9251 3172 5982 8035 6204 3500 6339 8814 8840 2508 6228 9200 7935 8523 7068 3424 8978 5768 7501 9646 4196 4442 1562 6767 4750 699 5440 3536 3021 9869 2557 86...

output:

46092817

result:

ok 1 number(s): "46092817"

Test #8:

score: 4
Accepted
time: 3ms
memory: 11940kb

input:

100 242
3134 6290 2028 5788 4211 5174 8943 9738 3101 3465 8440 7195 3100 4581 9130 9171 8974 6008 3340 4595 7981 4673 8045 5729 318 1540 7838 8989 7999 6723 1082 7485 9365 3110 9625 3576 8284 8568 9666 7737 8386 8107 4933 7838 9040 4063 7009 8014 6424 6702 2609 757 7727 7006 2838 8045 8547 676 3386 ...

output:

44375616

result:

ok 1 number(s): "44375616"

Test #9:

score: 4
Accepted
time: 75ms
memory: 40944kb

input:

2000 4112
26779 976630 629698 838829 389521 862251 947257 514503 617805 132461 607866 44377 350873 179482 566928 325116 804117 586046 224375 835815 73008 343942 478938 803688 478006 455172 287599 664808 238219 903563 191272 781350 880193 337322 620180 786066 199574 567437 300570 817379 216251 908436...

output:

179154172171

result:

ok 1 number(s): "179154172171"

Test #10:

score: 4
Accepted
time: 71ms
memory: 40136kb

input:

2000 3078
710547 800704 389233 426297 248061 311538 298118 618533 588412 931460 691070 142844 482279 337212 753229 865200 481226 754647 810665 820379 288775 340463 672271 365043 352450 327593 902549 960185 413895 662427 693615 640795 979483 82848 67092 227545 394386 365210 362430 499150 296670 53500...

output:

153264428626

result:

ok 1 number(s): "153264428626"

Test #11:

score: 4
Accepted
time: 63ms
memory: 39420kb

input:

2000 1999
166930 540835 250286 530842 904210 505986 17302 468571 320341 513224 581776 248811 71876 479371 30498 628106 957927 593197 661712 507635 561394 190520 323163 240198 692831 142822 433859 693483 564357 825223 36798 731287 366058 287085 778481 270268 793071 795783 255192 629764 825360 353320 ...

output:

110359043397

result:

ok 1 number(s): "110359043397"

Test #12:

score: 4
Accepted
time: 68ms
memory: 40928kb

input:

2000 1999
35646 276069 424835 116267 267230 37087 581298 27990 124912 618482 760369 528816 690861 521028 749762 349949 88882 476925 488810 182877 665305 877558 195331 335562 562923 315310 824349 947080 954329 92694 720537 989975 885115 661724 622594 152345 698812 203892 696688 823724 338726 457057 8...

output:

119719819907

result:

ok 1 number(s): "119719819907"

Test #13:

score: 4
Accepted
time: 59ms
memory: 40236kb

input:

2000 1999
199132 500679 118140 685637 909027 847523 976147 601329 812769 416069 880530 460623 262867 388831 256803 198617 281793 601423 958908 845940 121803 794897 12385 222169 579451 264125 730132 449275 742264 712367 335651 941397 729399 970143 143386 154778 817666 119534 756107 146787 535603 1529...

output:

121011944346

result:

ok 1 number(s): "121011944346"

Test #14:

score: 4
Accepted
time: 59ms
memory: 39608kb

input:

2000 1999
102742 814219 224423 344676 965917 769363 97225 29938 501493 889059 290531 887011 250476 134123 143578 506965 787535 986669 201754 880684 426854 323492 809285 801746 84856 422881 589691 93040 459328 946805 765960 562070 761024 990384 423098 243293 759747 520323 273231 261240 925734 80115 6...

output:

114482929099

result:

ok 1 number(s): "114482929099"

Test #15:

score: 4
Accepted
time: 73ms
memory: 42940kb

input:

2000 7330
171682 573847 532915 243280 486629 726740 573099 137061 88552 28997 97173 410808 566361 825443 602457 965890 29871 353470 205589 559029 358645 470605 770894 406455 725513 258327 869037 243755 387236 169452 902438 75270 743299 951705 318550 746280 194797 408001 399693 799702 436999 496866 2...

output:

123030193674

result:

ok 1 number(s): "123030193674"

Test #16:

score: 4
Accepted
time: 74ms
memory: 40324kb

input:

2000 7607
404325 845008 676918 613163 630390 967208 286361 542898 406915 374830 931767 729977 339138 553105 36622 507293 534789 908280 734880 616649 659367 258274 892577 60893 725788 720867 131878 92139 977925 555591 756098 382250 400600 433016 511765 547342 400224 798127 606592 323491 172957 538360...

output:

119251622077

result:

ok 1 number(s): "119251622077"

Test #17:

score: 4
Accepted
time: 76ms
memory: 40348kb

input:

2000 7634
767271 617869 739285 633369 699499 288381 259588 290331 184341 909322 341694 680151 320239 368895 614719 660782 637507 450080 752162 262663 290284 384380 439102 151804 647681 678043 347249 224509 596265 145724 853495 879889 763593 592780 513258 979444 397513 289198 269775 98206 714873 1278...

output:

121425993224

result:

ok 1 number(s): "121425993224"

Test #18:

score: 4
Accepted
time: 79ms
memory: 40056kb

input:

2000 9311
742392 661409 378517 358645 329434 865533 318187 828349 727175 444809 694401 552912 782039 925216 637692 665685 388122 362136 152354 135816 395573 606486 831380 671865 172958 480502 818190 852847 107712 992255 3510 850105 170017 382027 725102 499451 763912 43289 327801 7439 4450 538554 560...

output:

120044666114

result:

ok 1 number(s): "120044666114"

Test #19:

score: 4
Accepted
time: 72ms
memory: 26396kb

input:

700 4395
1646735 65920300 11194254 55770374 76274161 68998510 5341129 69290185 47129599 85643989 18364952 43222021 62065348 44325836 26631025 71945264 37324114 4982663 26071943 59389547 99728716 82021542 53144840 45403056 70559713 97446564 39009695 89953227 69743832 62441559 34505974 71390568 283618...

output:

17260814725524

result:

ok 1 number(s): "17260814725524"

Test #20:

score: 4
Accepted
time: 70ms
memory: 22376kb

input:

700 3987
80776893 48024023 56922117 99513476 85572091 53513664 56699888 72339506 62463947 57321279 16295258 53401593 66011554 96516260 34711108 59286750 13421039 50747768 36048008 74082879 27054427 225382 90643450 80764255 98452049 54372177 43170822 77425612 23437743 35661005 1735952 4214636 8368502...

output:

17149476904162

result:

ok 1 number(s): "17149476904162"

Test #21:

score: 4
Accepted
time: 74ms
memory: 22408kb

input:

700 2051
77248002 33990513 90931860 16228511 36242991 94218392 7435649 28437336 9912862 12148530 23499796 1633656 38001802 54671579 2216823 61882777 4380956 4816250 96831980 81221708 72173269 44828393 19981207 45461866 7212970 87898361 73898127 99830141 72937472 90228803 33825193 2701827 76735668 77...

output:

16571009695053

result:

ok 1 number(s): "16571009695053"

Test #22:

score: 4
Accepted
time: 351ms
memory: 40216kb

input:

2000 14105
12630675 27636673 98454796 56909988 90317098 3305666 78143689 81191662 61177424 75289883 23130276 27288364 93849627 73256127 47103140 68892474 34134420 81259804 88530657 56711765 11011809 99961099 57107160 74254238 82425215 35398221 19156470 67290723 92181194 97264827 42161180 4811869 774...

output:

60253763960960

result:

ok 1 number(s): "60253763960960"

Test #23:

score: 4
Accepted
time: 349ms
memory: 40336kb

input:

2000 19256
47935031 93693974 18823314 34612563 34567797 37255812 63772360 74598639 60098188 16260376 63464654 81911519 31737510 70543179 88081734 23983536 26519118 34254977 43671093 38682271 99170784 47799833 8293081 49711780 8843136 5049246 99198172 85623182 956134 99480425 45818790 48891166 931743...

output:

63889555833152

result:

ok 1 number(s): "63889555833152"

Test #24:

score: 4
Accepted
time: 400ms
memory: 39808kb

input:

2000 15824
95852670 75910489 5557846 86114269 92579959 52171421 94120433 55726616 77869148 29863952 39034031 24977193 95707810 57916683 61053346 71203152 47435485 22287358 81923164 81667448 94929611 23987098 44449903 60316988 64965876 90016381 96703712 92505275 93836674 12265270 61102451 89689344 40...

output:

87693275452817

result:

ok 1 number(s): "87693275452817"

Test #25:

score: 4
Accepted
time: 415ms
memory: 41688kb

input:

2000 20000
99622004 81222022 12621672 52959518 88799948 17290109 81969972 70200189 88434977 34886169 25284918 5712766 38356204 70141607 81940463 55482808 77518584 42110520 1955940 27741412 86495259 12006234 19169157 11814490 44811241 27825609 3986842 64703229 28969783 7421497 75156085 81108140 88643...

output:

96267890664770

result:

ok 1 number(s): "96267890664770"

Extra Test:

score: 0
Extra Test Passed