QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#401883#7403. Subset SumdefinierenAC ✓517ms5684kbC++204.8kb2024-04-29 16:04:362024-05-04 13:40:24

Judging History

你现在查看的是测评时间为 2024-05-04 13:40:24 的历史记录

  • [2024-11-08 21:20:19]
  • 自动重测本题所有获得100分的提交记录
  • 测评结果:AC
  • 用时:518ms
  • 内存:5824kb
  • [2024-11-08 21:19:40]
  • hack成功,自动添加数据
  • (/hack/1150)
  • [2024-07-11 20:10:26]
  • 自动重测本题所有获得100分的提交记录
  • 测评结果:100
  • 用时:515ms
  • 内存:4128kb
  • [2024-07-11 20:10:05]
  • hack成功,自动添加数据
  • (/hack/734)
  • [2024-05-30 11:42:42]
  • 自动重测本题所有获得100分的提交记录
  • 测评结果:100
  • 用时:519ms
  • 内存:5740kb
  • [2024-05-30 11:41:28]
  • hack成功,自动添加数据
  • (/hack/643)
  • [2024-05-24 18:17:23]
  • 自动重测本题所有获得100分的提交记录
  • 测评结果:100
  • 用时:516ms
  • 内存:4140kb
  • [2024-05-24 18:15:02]
  • hack成功,自动添加数据
  • (/hack/638)
  • [2024-05-04 13:43:51]
  • 自动重测本题所有获得100分的提交记录
  • 测评结果:100
  • 用时:516ms
  • 内存:5984kb
  • [2024-05-04 13:41:40]
  • hack成功,自动添加数据
  • (/hack/612)
  • [2024-05-04 13:40:24]
  • 自动重测本题所有获得100分的提交记录
  • 测评结果:100
  • 用时:517ms
  • 内存:5684kb
  • [2024-05-04 13:38:14]
  • hack成功,自动添加数据
  • (/hack/611)
  • [2024-04-29 16:04:38]
  • 评测
  • 测评结果:100
  • 用时:515ms
  • 内存:5892kb
  • [2024-04-29 16:04:36]
  • 提交

answer

#include <bits/stdc++.h>

#define fir first
#define sec second
#ifdef LOCAL
#define dbg(x) cerr << "In Line " << __LINE__ << " the " << #x << " = " << x << '\n';
#define dpi(x, y) cerr << "In Line " << __LINE__ << " the " << #x << " = " << x << " ; " << "the " << #y << " = " << y << '\n';
#define dbgf(fmt, args...) fprintf(stderr, fmt, ##args);
#else
#define dbg(x) void();
#define dpi(x, y) void();
#define dbgf(fmt, args...) void();
#endif

using namespace std;

using ll = long long;
using ull = unsigned long long;
using i128 = __int128_t;
using pii = pair<int, int>;
using pil = pair<int, ll>;
using pli = pair<ll, int>;
using vi = vector<int>;
using vpii = vector<pii>;

bool Mbe;
constexpr int MOD = 998244353;
template<typename T> T add(T a, T b, T p = MOD) { return (a + b >= p) ? (a + b - p) : (a + b); }
template<typename T> T del(T a, T b, T p = MOD) { return (a - b < 0) ? (a - b + p) : (a - b); }
template<typename T> T mul(T a, T b, T p = MOD) { return 1ll * a * b % p; }
template<typename T> T cadd(T &a, T b, T p = MOD) { return a = add(a, b, p); }
template<typename T> T cdel(T &a, T b, T p = MOD) { return a = del(a, b, p); }
template<typename T> T cmul(T &a, T b, T p = MOD) { return a = mul(a, b, p); }
template<typename T> T cmax(T &a, T b) { return a = max(a, b); }
template<typename T> T cmin(T &a, T b) { return a = min(a, b); }

namespace FastIO {
	constexpr int LEN = 1 << 20;
	char in[LEN + 1], out[LEN + 1];
	char *pin = in, *pout = out, *ein = in, *eout = out + LEN;

	char gc() { return pin == ein && (ein = (pin = in) + fread(in, 1, LEN, stdin), ein == in) ? EOF : *pin ++; }
	void pc(char c) { pout == eout && (fwrite(out, 1, LEN, stdout), pout = out); (*pout ++) = c; return; }
	void Flush() { fwrite(out, 1, pout - out, stdout); pout = out; }

	template<typename T> T Read() {
		T x = 0; int f = 1; char ch = gc();
		while (ch < '0' || ch > '9') f = (ch == '-' ? (~f + 1) : f), ch = gc();
		while (ch >= '0' && ch <= '9') x = (x << 1) + (x << 3) + (ch ^ 48), ch = gc();
		return x * f;
	}
	template<typename T> void Write(T x, char c) {
		static char stk[40]; int tp = 0;
		if (x < 0) pc('-'), x = ~x + 1;
		do stk[tp++] = x % 10 + 48, x /= 10; while (x);
		while (tp --) pc(stk[tp]); pc(c); return;
	}
	void Read(char *s) {
		char ch = gc();
		while (!((ch >= 'a' && ch <= 'z') || (ch >= 'A' && ch <= 'Z') ||
			(ch >= '0' && ch <= '9'))) ch = gc();
		while ((ch != EOF) && ((ch >= 'a' && ch <= 'z') || (ch >= 'A' && ch <= 'Z') ||
			(ch >= '0' && ch <= '9'))) *s = ch, s ++, ch = gc();
		*s = '\0'; return;
	}
	void Write(char *s) {
		while (*s != '\0') pc(*s), s ++; return;
	}
	void Puts(char *s) {
		Write(s), pc('\n'); return;
	}
}

#define getchar FastIO::gc
#define putchar FastIO::pc
#define Flush FastIO::Flush
#define Read FastIO::Read
#define Write FastIO::Write
#define Puts FastIO::Puts

constexpr int MAXN = 2e4 + 5, MAXV = 2e4 + 5;
int n, c, a[MAXN], mx;
int f[2][MAXV << 1];

int &F(int o, int i) { return f[o][i + mx]; }

void slv() {
	n = Read<int>(), c = Read<int>();
	for (int i = 1; i <= n; i ++)
		cmax(mx, a[i] = Read<int>());
	int pos = 0; int sum = 0;
	while (pos < n && sum + a[pos + 1] <= c)
		sum += a[++ pos];
	if (pos == n || sum == c) { Write(sum, '\n'); return; }
	int now = 0, nxt = 1;
	F(now, sum - c) = pos + 1;
//		cout << pos << ':' << endl;
//		for (int i = - mx + 1; i <= mx; i ++)
//			if (F(now, i)) cout << c + i << ' ' << F(now, i) << endl;
//		cout << endl;
	for (int r = pos; r < n; r ++) {
//		for (int i = mx; i < mx * 2; i ++) {
//			cmax(f[nxt][i], f[now][i]);
//			for (int l = f[now][i]; l < f[nxt][i]; l ++)
//				cmax(f[nxt][i - a[l]], l);
//		}
//		for (int i = 0; i < mx; i ++) {
//			cmax(f[nxt][i], f[now][i]);
//			cmax(f[nxt][i + a[r + 1]], f[now][i]);
//		}
		for (int i = - 1; i > - mx; i --) {
			cmax(F(nxt, i), F(now, i));
			cmax(F(nxt, i + a[r + 1]), F(now, i));
		}
		for (int i = mx - 1; i >= 0; i --) {
			cmax(F(nxt, i), F(now, i));
			for (int l = F(now, i); l < F(nxt, i); l ++)
				cmax(F(nxt, i - a[l]), l);
		}
		swap(now, nxt);
//		cout << r + 1 << ':' << endl;
//		for (int i = - mx + 1; i <= mx; i ++)
//			if (F(now, i)) cout << c + i << ' ' << F(now, i) << endl;
//		cout << endl;
	}
	int ans = 0;
	while (!F(now, ans)) ans --;
	Write(c + ans, '\n');
	return;
}
void clr() {
	for (int j = - mx + 1; j <= mx; j ++)
		for (int i : {0, 1}) F(i, j) = 0;
	mx = 0;
	return;
}

bool Med;
int main() {
#ifdef LOCAL
	freopen("!in.in", "r", stdin);
	freopen("!out.out", "w", stdout);
	fprintf(stderr, "%.3lf Mb\n", fabs((&Mbe - &Med) / 1048576.0));
#endif
//	int T = 1;
	int T = Read<int>();
	while (T --) slv(), clr();
	Flush();
#ifdef LOCAL
	fprintf(stderr, "%d ms\n", (int)clock());
#endif
	return 0;
}

这程序好像有点Bug,我给组数据试试?

詳細信息

Test #1:

score: 100
Accepted
time: 0ms
memory: 3488kb

input:

3
3 5
2 3 4
3 1
2 3 4
3 1000000000
2 3 4

output:

5
0
9

result:

ok 3 number(s): "5 0 9"

Test #2:

score: 0
Accepted
time: 448ms
memory: 5680kb

input:

100
63 133550
17234 638 8523 521 6421 19198 2712 17687 15811 11817 15849 16605 1708 12159 19831 3445 12529 5395 12206 6413 18377 12237 8080 4230 9407 15464 17360 12118 5457 18197 13144 12967 2675 4439 11235 4438 15498 678 6051 18356 18066 9068 1660 5640 6425 8106 16167 6316 6881 6068 13008 17228 98 ...

output:

133550
365866
455651
1072973
696051
849806
451783
329019
460849
243568
821923
519808
65293
722003
268371
12966
640372
91176
227453
478018
190943
1466983
672114
643379
417671
1304850
314401
88902
414529
252143
857248
22965
56336
1703029
967466
230626
125212
32989
236873
82417
387912
662080
946732
791...

result:

ok 100 numbers

Test #3:

score: 0
Accepted
time: 45ms
memory: 3600kb

input:

100
106 50478
1352 1958 1292 1856 1152 1541 1553 1094 1001 1181 892 1346 624 1023 1228 886 917 306 998 1132 431 688 1583 1807 629 166 35 1983 1941 280 1074 1681 1840 202 637 653 1532 216 1069 1438 1633 1183 1405 70 589 1761 299 1383 720 438 1195 1451 1280 981 100 1916 871 1119 1120 1724 1408 1333 19...

output:

50478
45653
12264
4428
84946
43070
57632
58033
65049
765
39927
6818
58269
32740
90653
6870
27952
106994
64599
47143
6487
4797
189721
19401
34242
34705
124517
52619
49055
78061
174213
22618
22336
134278
1863
122954
116301
60398
19103
22939
96159
71213
135142
55080
48203
49758
11901
8306
2782
100089
5...

result:

ok 100 numbers

Test #4:

score: 0
Accepted
time: 5ms
memory: 3600kb

input:

100
63 4789
82 28 49 194 174 175 77 157 120 141 7 42 196 75 86 171 5 12 15 180 153 22 31 133 24 182 108 12 176 48 149 192 84 151 69 95 24 131 4 161 151 94 134 50 86 174 18 100 102 135 52 155 101 62 139 199 94 86 187 173 76 71 53
115 9099
23 90 33 151 120 7 98 102 103 48 83 32 81 118 89 123 61 183 1 ...

output:

4789
9099
1064
2379
5349
2408
15292
3114
544
6462
3934
3384
16266
1012
2023
1923
4953
171
15786
5492
9634
2681
15324
4916
7675
16888
7776
5870
1713
1962
5617
9778
241
3929
78
4290
2782
209
6269
704
502
5278
1836
5775
12042
1157
2781
483
6720
4264
3452
12534
11440
1248
14487
5741
9753
330
8638
5397
7...

result:

ok 100 numbers

Test #5:

score: 0
Accepted
time: 295ms
memory: 3952kb

input:

10
1160 4680552
14978 7415 15122 16423 6430 5558 10869 12737 9227 15677 5545 19975 3653 2233 15922 15454 15289 2184 14665 3904 1036 14654 7002 11707 6674 5956 1799 13712 631 16948 12515 14133 9210 17726 5623 12020 685 17447 4640 13450 9367 17317 79 8937 5010 18468 18696 19990 14765 12196 17123 4939 ...

output:

4680552
4282752
530079
95385
1585230
362527
2864670
4664186
4203737
763035

result:

ok 10 numbers

Test #6:

score: 0
Accepted
time: 19ms
memory: 3540kb

input:

10
752 37012
853 1888 344 1574 750 1077 1123 1910 1083 1448 1366 1376 613 1530 45 435 522 810 758 1460 1418 65 1669 1804 1804 919 257 1286 1959 1018 1877 642 569 798 64 1509 804 1848 1749 967 604 178 1612 1683 1818 1755 847 922 636 1812 1454 1344 274 659 1115 1278 307 100 1087 1870 1238 1043 659 182...

output:

37012
98306
34284
601611
385732
155609
6564
408966
263837
187235

result:

ok 10 numbers

Test #7:

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

input:

10
1141 104699
84 76 129 97 173 88 133 10 170 165 75 43 62 28 160 150 14 172 4 127 52 89 49 56 189 49 192 154 170 22 100 163 51 86 52 83 7 110 69 46 149 83 94 173 182 159 75 20 176 18 179 78 125 134 50 124 114 34 47 114 48 49 7 11 183 88 72 191 134 147 135 164 92 184 3 18 194 98 7 6 71 95 76 16 59 1...

output:

104699
49134
133546
44571
106611
26282
10257
28481
3142
44075

result:

ok 10 numbers

Test #8:

score: 0
Accepted
time: 517ms
memory: 4140kb

input:

1
20000 133486437
9760 14402 14493 8153 8723 15946 5032 14575 11209 13193 5678 16284 17378 14678 10562 13910 15940 3275 14939 5755 4760 7782 17619 15914 4587 2536 1643 8103 3631 9273 7301 15996 12695 18786 4649 7667 9150 2097 8673 3773 193 11289 14204 11630 7648 911 15534 3646 15745 13134 10511 1152...

output:

133486437

result:

ok 1 number(s): "133486437"

Test #9:

score: 0
Accepted
time: 50ms
memory: 5684kb

input:

1
19998 12425665
1163 1478 876 333 1871 1515 175 322 244 1607 1822 1848 1524 1740 683 1627 715 1121 880 126 1933 592 710 1091 1774 728 1390 388 504 1003 1595 622 89 193 1302 417 1250 1332 121 1793 1321 386 85 472 376 1470 1980 1169 1484 704 1319 1071 1542 1120 929 340 1229 1182 841 826 1195 525 1413...

output:

12425665

result:

ok 1 number(s): "12425665"

Test #10:

score: 0
Accepted
time: 446ms
memory: 3976kb

input:

101
59 142633
11966 16383 15593 3668 15830 11706 13823 13451 5927 14112 5647 12867 13070 3458 5888 8230 1661 1667 15662 10736 17821 794 10284 18133 9031 915 16636 19513 18378 4366 6168 7926 9705 6335 877 6266 3226 5388 13627 998 4743 9298 11190 14448 16433 641 13832 13570 3528 603 14605 856 3924 607...

output:

142633
100389
75454
207625
323199
752180
183578
727450
366962
531604
223686
407596
46087
501868
765383
207818
235484
132311
123265
685660
555
116111
269446
296167
255307
0
123156
300520
384150
341568
25155
251433
436722
12114
37914
240792
458220
416297
475485
86791
650154
374621
73377
22742
115929
2...

result:

ok 101 numbers

Extra Test:

score: 0
Extra Test Passed